

# How AWS Context answers questions over structured data

When a question needs data, the retrieval agent writes and runs the query for you:

1. It searches the Agent context for the tables, columns, metrics, business rules, verified queries, and skills that match the question.

1. It reads their definitions. A metric formula or verified query is used exactly as written.

1. It writes one read-only SQL query and runs it against the source.

1. It writes the answer, citing the query result and the definitions it used.

The query appears on the result in `properties.sourceQuery`. If a query fails, the agent reads the error, fixes the query, and tries again within its step limit. To write and run the query yourself, see [Query tables with ExecuteSql](query-tables-with-executesql.md).

The agent sees at most 50 rows and 20,000 characters of each result, and it is instructed to aggregate in SQL. Answers over large tables are computed by the source, not by reading rows.

Answer quality depends mostly on metadata:
+ Describe your tables and columns in your catalog, and define your terms and metrics. A column named `amt_2` with no description is a guess.
+ Add verified queries and metric definitions for calculations people get wrong, such as an exposure-weighted average instead of a simple average.
+ Keep column-name case identical in the catalog and the data files. If the schema has `OrderDate` and the Parquet file has `orderdate`, the query is rejected.