NL2SQL: descriptions, mandatory constraints, and dynamic queries¶
Expand Advanced configuration under Semantic configuration → NL2SQL semantics to access table and field descriptions, mandatory constraints, and dynamic queries. Creation may be disabled until the knowledge base has usable structured data; prepare its data source first.
Table and field descriptions¶
These describe stable business meanings. Native database comments and supplementary descriptions are kept separately so existing metadata can be distinguished from maintained business context.
Select a table, read its description, and add supplementary information. Search by column name or description, supplement the relevant columns, and check their enabled selections. If the table lacks a native description, explain its business purpose and scope.
For example, define amount as “tax-inclusive amount in yuan” and explain status values. Save and check whether queries and answers interpret those fields correctly.
Mandatory constraints¶
A mandatory constraint adds fixed filters to queries involving a particular table. Each constraint binds to one table; when that table participates in a query, its conditions are added to SQL.
Create a constraint, enter its identifier, and select the table.
Add fields, comparisons, and values. Combine them with AND, OR, and groups as needed.
Inspect parentheses and scope in the WHERE preview.
Save and test questions that include and exclude the target data.
For example, a currency condition can restrict business calculations to CNY records. Query-definition settings do not replace database access permissions. Manage target-system data permissions separately.
See Filters and condition groups for condition composition.
Dynamic queries¶
Dynamic queries execute predefined read-only SQL when needed to supply current business data, such as an account mapping or business dictionary.
Create a query with an identifier, description, SQL, and result-handling method. Describe its purpose, returned content, and applicable scenarios.
Result handling |
Behavior |
Suitable when |
|---|---|---|
Analyze with a sub-agent |
Filters, summarizes, and analyzes results before passing the analysis to the main agent |
Results are large and need preparation |
Inject directly into the main agent’s context |
Passes the complete raw result to the main agent |
Results are small and raw detail matters |
SQL must be a single read-only SELECT or WITH query. Writes, schema changes, and multiple statements are prohibited. Dynamic-query SQL is limited to 16 KiB. Pass page validation, save, and inspect both actual data and the answer’s use of it.
Return only the fields and scope needed for the answer. Avoid injecting large volumes of unrelated detail. When using sub-agent analysis, verify that the summary preserves key conditions.
Verify changes¶
Reopen settings to confirm saved values and test a small data range. Check configuration, generated or executed SQL, returned data, and the final answer separately.