Overview
Thepresent_sql tool parses, validates, and presents SQL queries in a structured format. It’s designed for building alerts, saved queries, and iterative query construction workflows.
This tool does NOT execute queries. It validates and structures them for user review or storage. Use
execute_query for running queries.When to use
Usepresent_sql when:
- Creating an alert that will run on a schedule
- Saving a query for later use
- Building a query iteratively with user feedback
- Validating query structure before execution
- Presenting query details to users for approval
Prerequisites
Parameters
SQL query to parse and present. Should be built after calling
prepare_gdelt_query.Must include same requirements as execute_query:- Date filter (e.g.,
WHERE day >= today() - INTERVAL 7 DAY) - LIMIT clause (maximum 1000)
- Source URL column (
source_urlordocument_identifier)
Natural language description of what this query does.Examples:
- “Find protests in France over the last 7 days”
- “Track climate change articles with high negative tone”
- “Monitor China-Taiwan military events”
Concise title for this query (e.g., ‘Climate Protests in Europe’, ‘US Political Events’).Example: “France Protest Monitor”
Response
Returns aPresentSqlResult object with detailed query analysis:
The complete SQL query (echoed back).
The natural language description you provided.
List of tables referenced in the query.Automatically parsed from the FROM and JOIN clauses.
List of columns in the SELECT clause.Helps users understand what data they’ll receive.
List of filters from the WHERE clause.Shows users exactly what filtering logic is being applied.
Whether the query passed all validation checks.
true if all requirements met, false if issues found.Detailed validation results or error message.Explains what passed/failed and provides guidance for fixes.
Usage examples
Query workflow for alerts
1
Prepare query context
Call
prepare_gdelt_query to get schemas and codes.2
Build SQL query
Construct your SELECT query with:
- Appropriate date filter for the alert frequency
- Required LIMIT clause
- Source URL column
- Filters that define what you’re monitoring
3
Present and validate
Call
present_sql with descriptive information.Query is parsed, validated, and ready for review.
4
Review or iterate
Check validation results:
- If
validation_passed = true→ proceed to create alert - If
validation_passed = false→ reviewvalidation_messageand adjust query
Validation rules
Date filter validation
Date filter validation
Requirement: Must include date/time filter in WHERE clauseChecked patterns:
WHERE day >= today() - INTERVAL X DAYWHERE date_time >= now() - INTERVAL X HOURWHERE day BETWEEN ... AND ...
- Daily alerts: Use
day >= today() - INTERVAL 1 DAY - Hourly alerts: Use
date_time >= now() - INTERVAL 1 HOUR - Weekly alerts: Use
day >= today() - INTERVAL 7 DAY
LIMIT clause validation
LIMIT clause validation
Requirement: Must include LIMIT (max 1000)Valid:
LIMIT 100, LIMIT 500, LIMIT 1000For alerts: Consider your expected result volume:- High-frequency events: Use lower limits (50-100)
- Rare events: Can use higher limits (500-1000)
Source URL validation
Source URL validation
Requirement: Must select
source_url or document_identifierWhy for alerts: Users need to click through to original articles when they receive notifications.Table name validation
Table name validation
Requirement: Only use valid GDELT table namesValid tables:
- gdelt_events
- gdelt_mentions
- mv_event_mention_stats
- gdelt_gkg_themes_extracted
- gdelt_gkg_persons_extracted
- gdelt_gkg_organizations_extracted
- gdelt_gkg_locations_extracted
- gdelt_persons_master
- gdelt_organizations_master
Parsed output explanation
Tables parsed
Extracted from FROM and JOIN clauses. Helps users understand data sources. Example query:Columns returned
Extracted from SELECT clause. Shows what data users will receive. Example query:Filters applied
Extracted from WHERE clause. Documents the filtering logic. Example query:Alert creation patterns
Daily protest monitor
Hourly trending events
Weekly theme tracker
Person mention alert
Iterative query building
1
Start with simple query
Begin with basic filters to understand data volume.Check
columns_returned and filters_applied to verify structure.2
Add specific filters
Refine based on initial results.Review
filters_applied to ensure logic is correct.3
Optimize and finalize
Adjust LIMIT, add ORDER BY, include title.
Query is validated and ready for alert creation.
Best practices
Verify before creating alert - Always check
validation_passed is true before proceeding to alert creation.Error handling
Missing date filter
Missing date filter
Validation message: “Query must include date filter”Solution: Add WHERE clause with date/time comparison:
Missing LIMIT clause
Missing LIMIT clause
Validation message: “Query must include LIMIT clause”Solution: Add LIMIT at end of query:
Missing source URL
Missing source URL
Validation message: “Query must select source_url or document_identifier”Solution: Include in SELECT clause:
Invalid table name
Invalid table name
Validation message: “Table ‘xyz’ not found in GDELT schema”Solution: Use only valid table names from the 9 available GDELT tables.

