# SQL Context Sufficiency

**Objective:**\
This metric evaluates whether the context provided alongside the SQL prompt is sufficient to enable the model to generate a correct SQL query. It examines if the context contains all necessary details, such as column names, data types, and constraints, to ensure that the SQL query aligns with the expected output. An LLM is used to determine if the context provided is adequate or if additional information is required.

**Required Columns in Dataset:**

* **Prompt**: The SQL prompt or task description provided to the model.
* **Context**: Additional information or dataset details that clarify the prompt and guide the SQL generation.

**Interpretation:**\
A higher score indicates that the context is sufficient and provides all the necessary information for the model to generate the correct SQL query. A lower score suggests that the context is insufficient or lacks critical details, which may lead to errors in the generated SQL query.

\
Metric Execution via UI:

<figure><img src="/files/F2LeASvrfqF648HS7W49" alt=""><figcaption></figcaption></figure>

**Code Execution:**

```python
# SQL Context Sufficiency
metrics = [
    {"name": "SQL Context Sufficiency", "config": {"model": "gpt-4o-mini", "provider":"azure"}, "column_name":"SQL_Context_Sufficiency_v2"},
    {"name": "SQL Context Sufficiency", "config": {"model": "gpt-4o-mini", "provider":"openai"}, "column_name":"SQL_Context_Sufficiency_v2"}
]
```

#### Example:

**Prompt:**\
\&#xNAN;*Retrieve the names and ages of students with grade A.*

**Context:**\
\&#xNAN;*The dataset contains information about students, including their grades.*

**Metric Score:**\
**Score:** 0.3/1.0

**Reasoning:**

* **Insufficient Context:** While the context mentions that the dataset contains information about students and their grades, it fails to specify important details such as the exact column names (`student_name`, `student_age`), the existence of an `is_enrolled` column, and whether there are any constraints on the data.
* **Missing Critical Details:** The lack of specific information about the dataset structure makes it difficult for the model to generate an accurate SQL query, as it may make incorrect assumptions or miss relevant conditions.

**Interpretation:**\
The low score reflects that the context was insufficient to guide the model effectively. For accurate SQL query generation, the context should include all necessary details, such as column names, data types, and relevant constraints, to ensure the model has enough information to work with.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.raga.ai/ragaai-catalyst/ragaai-metric-library/text-to-sql/sql-context-sufficiency.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
