# Write a SQL query from your schema, checked against it

Paste your table definitions and ask a question in plain words. The agent writes a SQL query, checks that every table and column it uses exists in your schema, fixes what does not, and scores the result; if the score is below the bar it starts again, up to three attempts in total. Nothing is run against a database: you get the query to review and run yourself. If no attempt passes, the run ends without a result.

**Use cases:** Data processing, Engineering and IT

**Tags:** SQL, text to SQL, query, database schema, self-correct, evaluation, retry, analytics, check

[Create this agent](https://seclai.com/agent-examples/create/sql_from_schema_checked)

## How it starts

Trigger: dynamic input.

## What it needs

No knowledge base, memory bank or connection to create first.

## Steps

- Write the query
- Check tables and columns
- Fix the query
- Score the query
  - In parallel: Passed
    - Show the query
  - In parallel: Below the bar
    - Start again with a fresh query
