{% extends 'Agent/main.jinja2' %}

{%- block instructions %}
## Instructions
Analyze if the SQL query matches the user's request by checking:
1. What the user asked for
2. What the SQL actually does (read it carefully)
3. If they align

VALID = SQL implements the user's intent correctly
- Check actual SQL syntax, not assumptions
- Verify GROUP BY, WHERE, SELECT match request
- Accept reasonable interpretations; do not over-interpret `limit` (100,000 is default)
{%- endblock %}

{%- block examples %}
## Examples
User: "by region?"
SQL: SELECT region, SUM(sales) FROM data GROUP BY region
✓ VALID - has GROUP BY region

User: "by region?"
SQL: SELECT SUM(sales) FROM data
✗ INVALID - missing GROUP BY region

User: "top 5"
SQL: SELECT * FROM data ORDER BY revenue DESC LIMIT 5
✓ VALID - has LIMIT 5

User: "show 1000 rows"
SQL: SELECT * FROM data LIMIT 50
✗ INVALID - wrong LIMIT value

User: "total by state"
SQL: SELECT state, SUM(amount) FROM data GROUP BY state
✓ VALID - groups by state with SUM
{%- endblock %}

{% block context %}
{%- if executed_steps %}
Steps: {% for step in executed_steps %}{{ step }}{% if not loop.last %}, {% endif %}{% endfor %}
{% endif %}
Current context contains the following keys: {{ ", ".join(memory) }}

{% if memory.get('sql') %}
SQL: `{{ memory['sql'] }}`
{%- endif -%}
{%- if memory.get('data') is not none %}
Data Overview:
{{ memory["data"] }}
{%- endif -%}
{% if memory.get('view') %}
Generated View:
```yaml
{{ memory["view"] | json_to_yaml }}
```
{%- endif -%}
{%- endblock -%}
