Skip to main content

Documentation Index

Fetch the complete documentation index at: https://docs.agno.com/llms.txt

Use this file to discover all available pages before exploring further.

A model knows SQL but it does not know that revenue was replaced by revenue_v2 last March, that “active” excludes trialing accounts, or that MRR is computed net of credits. Grounding provides the missing context. The agent retrieves the relevant context for each question before it writes a line of SQL.
from agno.agent import Agent
from agno.knowledge.knowledge import Knowledge
from agno.models.openai import OpenAIResponses
from agno.tools.sql import SQLTools
from agno.vectordb.pgvector import PgVector

knowledge = Knowledge(
    vector_db=PgVector(table_name="dash_knowledge", db_url="postgresql+psycopg://ai:ai@localhost:5532/ai"),
)

agent = Agent(
    model=OpenAIResponses(id="gpt-5.5"),
    tools=[SQLTools(db_url="postgresql+psycopg://readonly@warehouse/analytics")],
    knowledge=knowledge,
    search_knowledge=True,
    instructions="Retrieve relevant query patterns and table notes before writing SQL.",
)
search_knowledge=True lets the agent pull the matching context per question instead of carrying the entire data dictionary in every prompt.

The layers worth curating

A production data agent grounds each answer in several layers. The first set is curated and stored in a vector database. The rest are live.
LayerSourceCurated?
Validated queriesKnown-good SQL for common questionsYes, in knowledge
Table metadataWhat each table and column actually meansYes, in knowledge
Business rulesDefinitions: what “active”, “MRR”, “churn” mean hereYes, in knowledge
Institutional knowledgeAn MCP server into your wiki or docsLive
LearningsFixes the agent captured from past errorsLive, see Self-correcting agents
Runtime schemadescribe_table at query timeLive

Validated queries are the highest-leverage layer

One known-good query for “monthly recurring revenue” is worth more than a page of schema notes. When the agent retrieves a validated query for a similar question, it adapts a correct shape instead of inventing one. Seed the store with the queries your analysts already trust.

Grounding vs raw text-to-SQL

Raw text-to-SQLGrounded data agent
Guesses column meaning from namesReads curated table metadata
Reinvents each query from scratchAdapts a validated query
”Active” means whatever the model assumes”Active” means what your business rule says
Wrong in a way that looks rightWrong in a way you can trace to a missing rule

Next steps

TaskGuide
Capture fixes as durable contextSelf-correcting agents
Run the SQL safelySafe data access

Developer Resources