Raw SQL query results often require manual interpretation before they can inform a decision or appear in a report. NL2SQL_SUMMARY eliminates that step by generating a written analytical summary directly from your query results — giving you a narrative interpretation, outlier highlights, or a report-ready paragraph without additional processing.
How it works
NL2SQL_SUMMARY runs as a two-stage pipeline:
-
The natural language to SQL (NL2SQL) model converts a plain-language question into a SQL query statement.
-
The
NL2SQL_SUMMARYmodel executes that SQL statement against your data and returns a written summary of the results.
Summarize query results
Step 1: Generate a SQL query statement
Use the NL2SQL model to convert your question into SQL:
/*polar4ai*/SELECT * FROM PREDICT (MODEL _polar4ai_nl2sql, select 'Query the credit score of each merchant') WITH (basic_index_name='schema_index',pattern_index_name='pattern_index');
The model returns a SQL query statement. For example:
SELECT merchname AS merchant_name, limitscore AS credit_score FROM hkrt_merchant_info ORDER BY limitscore;
Tip: Review the generated SQL before passing it to NL2SQL_SUMMARY. Confirming that the query matches your intent helps ensure the summary is accurate.
Copy the generated SQL query statement. You will use it in the next step.
Step 2: Generate a summary
Pass the SQL query statement to NL2SQL_SUMMARY, replacing <SQL_statement> and <usr_query> with your values:
/*polar4ai*/SELECT * FROM PREDICT (MODEL _polar4ai_nl2sql_summary,<SQL_statement> WITH (usr_query = <usr_query>);
Parameters
| Parameter | Description | Example |
|---|---|---|
<usr_query> |
The question you want answered. A specific, goal-oriented query produces a more relevant summary. | 'Merchant type distribution' |
<SQL_statement> |
The SQL query statement generated by NL2SQL. Do not add a semicolon at the end. | SELECT merchname AS merchant_name, limitscore AS credit_score FROM hkrt_merchant_info ORDER BY limitscore |
Example
/*polar4ai*/SELECT * FROM PREDICT (MODEL _polar4ai_nl2sql_summary,
SELECT merchname AS merchant_name, limitscore AS credit_score FROM hkrt_merchant_info ORDER BY limitscore
) WITH (usr_query='Query the credit score of each merchant');
Output:
This query returned the credit scores for 15 merchants, ranging from 60 to 95. The lowest score is 60 (Future Star Merchant), and the highest is 95 (Tech City Merchant). Overall, most merchants have scores above 70, indicating good credit standing.
SQL query results:
| No. | Credit score | Merchant name |
|---|---|---|
| 1 | 60 | Future Star Merchant |
| 2 | 65 | Stellar Tech Merchant |
| 3 | 68 | Innovative Future Merchant |
| 4 | 70 | Stellar Glory Merchant |
| 5 | 72 | Stellar Dream Merchant |
| 6 | 75 | Future Tech Merchant |
| 7 | 80 | Dream Tech Merchant |
| 8 | 82 | Dream Tech Merchant |
| 9 | 85 | Xiaotian Tech Merchant |
| 10 | 85 | Glorious Dream Merchant |
| 11 | 88 | Glorious Future Merchant |
| 12 | 90 | Glorious Tech Merchant |
| 13 | 90 | Glorious Star Merchant |
| 14 | 92 | Tech Star Merchant |
| 15 | 95 | Tech City Merchant |
Use cases
| Scenario | Example |
|---|---|
| Data overview | A data analyst needs to understand credit score distribution across merchant categories. NL2SQL_SUMMARY returns a written breakdown — no manual row-by-row interpretation required. |
| Decision support | A business manager needs a weekly summary of regional sales trends to present to stakeholders. NL2SQL_SUMMARY converts query results into a ready-to-share narrative. |
| Anomaly detection | An operations team queries transaction data to identify unusual patterns by category. NL2SQL_SUMMARY flags outliers and describes possible causes. |
| Report writing | A reporting workflow requires key data sections in plain language. NL2SQL_SUMMARY generates written content directly from query results. |
Best practices
-
Write a specific
usr_query. The more clearly you state the analytical goal, the more relevant the summary. For example,'Merchant type distribution'produces a more targeted result than a vague description. -
Chain NL2SQL and
NL2SQL_SUMMARYtogether to automate the full flow from a natural language question to a written summary. -
Use NL2Chart alongside
NL2SQL_SUMMARYto complement written summaries with visualizations.
NL2SQL_SUMMARY quickly extracts key information from raw data and creates structured summaries. This provides a solid foundation for subsequent data analytics and decision-making.