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

{%- block instructions %}
# Evaluate Discovery Sufficiency

Review the discovery results and determine if they provide enough context to fix the original SQL error.

## Evaluation Criteria

✅ SUFFICIENT if discoveries reveal:
- Column names that fix "column not found" errors
- Data formats that explain type conversion issues  
- Join key values that show overlap/compatibility between tables
- Date ranges that explain "no data returned" issues
- Value variations that show actual data format vs expected format
- Clear path forward to generate working SQL

❌ INSUFFICIENT if discoveries show:
- No matching values between potential join keys
- Limited data range that doesn't cover the query period
- Ambiguous column names that need more investigation
- Format inconsistencies requiring deeper exploration
- Pattern too narrow - need broader search or different pattern
- Schema only - when filter values failed but only table schemas were discovered

⚠️ CRITICAL: If original query failed due to filter values (e.g., WHERE clause returned empty), schema information alone is NEVER sufficient. You must see the actual distinct values for those filter columns.

## Follow-up Strategy
If insufficient, specify targeted follow-ups:
- More distinct values: Use OFFSET to see different value ranges
- Pattern refinement: Try different patterns or search terms
- Broader search: Remove pattern to see all values if pattern was too narrow
- Different columns: Sample other potential join/date columns
- Different tables: Check related tables for missing context
- Filter value discovery: When WHERE clause failed, sample DISTINCT values for each filter column to understand actual data format
  - Use pattern matching first when the original query contains specific search terms (e.g., if query failed with a country name, use a pattern to find country variations)
  - Use full distinct query for generic columns like medal_type, participant_type where you need to see all possible values

Goal: Minimal follow-ups that directly address the gap in understanding.
{%- endblock %}

{%- block context %}
{%- if error_context %}Original Error: {{ error_context }}{% endif %}

## Data summary
{{ memory["metaset"].compact_context(n=3, n_others=17) }}

## Discovery Results
{% for query_type, result in discovery_results %}
{{ query_type }}: {{ result }}
{% endfor %}

Your task: Determine if these discoveries provide enough context to fix the original error, or if specific follow-ups are needed.
{% endblock %}
