MCPcopy Index your code
hub / github.com/simstudioai/sim / enrichTableToolDescription

Function enrichTableToolDescription

apps/sim/lib/table/llm/enrichment.ts:32–121  ·  view source on GitHub ↗
(
  originalDescription: string,
  table: TableSummary,
  toolId: string
)

Source from the content-addressed store, hash-verified

30 * Enriches a table tool description with table information based on the operation type.
31 */
32export function enrichTableToolDescription(
33 originalDescription: string,
34 table: TableSummary,
35 toolId: string
36): string {
37 if (!table.columns || table.columns.length === 0) {
38 return originalDescription
39 }
40
41 const columnList = table.columns.map((col) => ` - ${col.name} (${col.type})`).join('\n')
42
43 if (FILTER_OPERATIONS.has(toolId)) {
44 const stringCols = table.columns.filter((c) => c.type === 'string')
45 const numberCols = table.columns.filter((c) => c.type === 'number')
46
47 let filterExample = ''
48 if (stringCols.length > 0 && numberCols.length > 0) {
49 filterExample = `
50
51Example filter: {"${stringCols[0].name}": {"$eq": "value"}, "${numberCols[0].name}": {"$lt": 50}}`
52 } else if (stringCols.length > 0) {
53 filterExample = `
54
55Example filter: {"${stringCols[0].name}": {"$eq": "value"}}`
56 }
57
58 let sortExample = ''
59 if (toolId === 'table_query_rows' && numberCols.length > 0) {
60 sortExample = `
61Example sort: {"${numberCols[0].name}": "desc"} for highest first, {"${numberCols[0].name}": "asc"} for lowest first`
62 }
63
64 const queryInstructions =
65 toolId === 'table_query_rows'
66 ? `
67INSTRUCTIONS:
681. ALWAYS include a filter based on the user's question - queries without filters will fail
692. Construct the filter yourself from the user's question - do NOT ask for confirmation
703. Use exact match ($eq) by default unless the user specifies otherwise
714. For ranking queries (highest, lowest, Nth, top N):
72 - ALWAYS use sort with the relevant column (e.g., {"salary": "desc"} for highest salary)
73 - Use limit to get only the needed rows (e.g., limit=1 for highest, limit=2 for second highest)
74 - For "second highest X", use sort: {"X": "desc"} with limit: 2, then take the second result
755. Only use limit=1000 when you need ALL matching rows`
76 : `
77INSTRUCTIONS:
781. ALWAYS include a filter based on the user's question - queries without filters will fail
792. Construct the filter yourself from the user's question - do NOT ask for confirmation
803. Use exact match ($eq) by default unless the user specifies otherwise`
81
82 return `${originalDescription}
83${queryInstructions}
84
85Table "${table.name}" columns:
86${columnList}
87${filterExample}${sortExample}`
88 }
89

Callers 1

enrichTableToolSchemaFunction · 0.90

Calls 1

joinMethod · 0.80

Tested by

no test coverage detected