> ## Documentation Index
> Fetch the complete documentation index at: https://futureagi.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# Text to SQL

> Evaluates the accuracy and quality of SQL queries generated from natural language instructions.

<CodeGroup>
  ```python Python theme={null}
  result = evaluator.evaluate(
      eval_templates="text_to_sql",
      inputs={
          "input": "List the names of all employees who work in the sales department.",
          "output": "SELECT name FROM employees WHERE department = 'sales';"
      },
      model_name="turing_flash"
  )

  print(result.eval_results[0].output)
  print(result.eval_results[0].reason)
  ```

  ```typescript JS/TS theme={null}
  import { Evaluator, Templates } from "@future-agi/ai-evaluation";

  const evaluator = new Evaluator();

  const result = await evaluator.evaluate(
    "text_to_sql",
    {
      input: "List the names of all employees who work in the sales department.",
      output: "SELECT name FROM employees WHERE department = 'sales';"
    },
    {
      modelName: "turing_flash",
    }
  );

  console.log(result);
  ```
</CodeGroup>

| **Input** |                    |          |                                            |
| --------- | ------------------ | -------- | ------------------------------------------ |
|           | **Required Input** | **Type** | **Description**                            |
|           | `input`            | `string` | The natural language query or instruction. |
|           | `output`           | `string` | The generated SQL query.                   |

| **Output** |            |                                                                                                             |
| ---------- | ---------- | ----------------------------------------------------------------------------------------------------------- |
|            | **Field**  | **Description**                                                                                             |
|            | **Result** | Returns Passed if the SQL query correctly represents the natural language request, or Failed if it doesn't. |
|            | **Reason** | Provides a detailed explanation of why the SQL query was classified as correct or incorrect.                |

***

### What to do If you get Undesired Results

If the SQL query is evaluated as incorrect (Failed) and you want to improve it:

* Ensure the SQL syntax is correct and follows standard conventions
* Verify that all tables and columns referenced match the database schema implied by the natural language query
* Check that the query filters for exactly the data requested (no more, no less)
* Make sure appropriate joins are used when multiple tables are involved
* Confirm that the query handles potential edge cases like NULL values appropriately
* Use the correct data types for values in comparisons (e.g., quotation marks for strings)
* For complex queries, consider breaking them down into simpler parts for troubleshooting

***

### Comparing Text to SQL with Similar Evals

* [**Task Completion**](/future-agi/get-started/evaluation/builtin-evals/task-completion): While Text to SQL focuses specifically on converting natural language to SQL queries, Task Completion evaluates whether a response completes the requested task more generally.
* [**Evaluate Function Calling**](/future-agi/get-started/evaluation/builtin-evals/llm-function-calling): Text to SQL evaluates SQL generation specifically, whereas Evaluate Function Calling assesses the correctness of function calls and parameters more broadly.
* [**Is Code**](/future-agi/get-started/evaluation/builtin-evals/is-code): Text to SQL evaluates the correctness of SQL generation, while Is Code detects whether content contains code of any type.
