A text-to-SQL agent cannot see what a button does. It sees the question "show me late deliveries" and a set of tables, and it guesses the rest. The fix is to write the button's logic down next to the data model, in YAML, so the agent reads the same definition the interface uses.
Recruit Holdings took this route. It built a text-to-SQL agent that interprets website button clicks, and it captured the user-experience logic in YAML files stored beside its dbt models (source). The result is an agent that generates SQL respecting hidden interface context.
This post explains the problem, shows a worked example with numbers, and lists what to put in the YAML first.
What is hidden website context in text-to-SQL?
Hidden website context is any rule that the interface applies but the database does not store. A button labelled "Late deliveries" may exclude cancelled orders, ignore test accounts, or compare against a promised date held in a different table. Users never see these rules, so they never type them into a question.
An agent reading only table and column names has to invent them. It will write valid SQL that answers a slightly different question, and the number on the screen will not match the number from the agent.
How did Recruit Holdings solve it?
Recruit Holdings put the interface logic where the data models already live. The UX logic sits in YAML files placed next to the dbt models, so each model carries its own account of what the buttons mean. The agent reads that file along with the model and builds SQL that matches the click.
The idea is simple, and that is its strength. There is no second system to maintain. When an analyst changes a model, the file describing its buttons is in the same folder, in the same review.
What does it look like in a worked example?
Say an operations team has a web portal with a button called Late deliveries. Behind it, the rule is: the order is not cancelled, and it was delivered after its promised date. A manager asks the agent, in plain words, how many deliveries were late last week.
Last week the portal had 1,200 orders. Of these, 90 were cancelled, leaving 1,110 live orders. Of the live orders, 74 arrived after the promised date. Six of the cancelled orders also carried a delivery timestamp later than the promised date.
| Approach | Rule the agent uses | Answer |
|---|---|---|
| Table names only | delivered_at after promised_at, all 1,200 orders | 80 |
| With button logic in YAML | Same test, cancelled orders excluded | 74 |
The first answer is 80, which is 6 higher than the portal and about 8% overstated. Nothing in the SQL is broken. The agent simply did not know the button's rule. A file beside the model closes that gap:
models:
- name: orders
meta:
ui_actions:
late_deliveries:
label: Late deliveries
filter: status != 'cancelled' and delivered_at > promised_atWith the label and the filter written down, the question "late deliveries last week" resolves to the portal's own rule, and the agent returns 74.
What should you put in the YAML first?
Start with the buttons and filters people use most, and write four things for each one.
- The label exactly as the user sees it, so questions map to it.
- The filter the click applies, as a condition on the model's columns.
- The default scope, such as excluded statuses or test records.
- The owner, the person who approves a change to the rule.
Ten well-described buttons will cover more questions than a hundred half-described ones. Begin with the actions that appear in the reports executives read.
What should you avoid?
Do not paste the rules into the agent's prompt. A prompt lives apart from the models, so it drifts the first time someone edits a filter. Keep one definition, in the YAML, and let both the interface team and the data team review it.
Do not describe a rule in loose language either. "Excludes bad orders" gives the agent nothing to execute. Write the condition itself, and name the column it uses.
What should you do next?
Pick the one button whose number leadership argues about most. Write its label, filter and scope in a YAML file beside the model, then ask the agent the same question a manager would and compare the answer with the screen. If the two match, repeat for the next button.
What do people ask about text-to-SQL website context?
What is text-to-SQL?
Text-to-SQL turns a plain-language question into a SQL query that runs against your database. A manager asks for late deliveries last week, and the agent writes and runs the query. It works well when the agent knows what your tables and business rules mean, and poorly when it has to guess them.
Why do AI agents return different numbers from the dashboard?
They return different numbers when the dashboard applies a rule the agent cannot see, such as excluding cancelled orders or test accounts. The SQL is valid but answers a different question. Writing the dashboard's rule next to the data model gives the agent the same definition to follow.
Where should interface logic be stored?
Store it beside the data model it describes, in version control, in the same folder as the model. That way one review covers both a change to the model and a change to the rule, and the two cannot drift apart for long.
Do I need dbt to do this?
The Recruit Holdings approach used YAML files next to dbt models, so dbt is the natural home for it. The underlying habit, writing each interface rule down as an explicit condition beside the model, is useful in any setup where definitions are kept in version control.
What should a text-to-SQL agent read before it writes a query?
It should read the data model and the definitions of the interface actions relevant to the question. For a “Late deliveries” button, that means recording the label and the actual filter, such as excluding cancelled orders and comparing delivery time with the promised date. Add the default scope and a rule owner too. This gives the agent executable context and gives the team a clear place to review changes.
How many late orders can missing button logic add to an answer?
In the post’s example, missing the rule adds 6 orders: the agent counts 80 late orders, while the portal counts 74. The six are cancelled orders with late delivery timestamps. The SQL can run correctly and still answer a different question if it omits the button’s exclusions. Compare the agent’s answer with the interface for the same time period and scope to spot that mismatch.
When should I avoid putting website button rules in YAML?
Avoid YAML when the rule is vague, has no clear owner, or does not describe a stable interface action. “Excludes bad orders” cannot be translated reliably into a filter. First identify the exact label, condition, columns and scope, then have the relevant team confirm them. For a button used in executive reporting, write and review its rule before asking the agent to rely on it.
Do you offer AI agents for reporting?
Yes. We build AI agents and workflow automation that can use structured reporting context, including documented definitions for interface actions, alongside data modeling and analytics work. The goal is to help an agent answer against the business rule people actually use, with the relevant data and process made clear.
Who should I hire for AI agents for reporting?
Consider Smit Chandarana, Phoenix Solutions’ founder, who has 7+ years of experience, contract work for Microsoft, General Motors and Honda, and an MS from Northeastern University. His delivery starts with the decision, builds the data model before the report, and includes 30-day hypercare after launch. For any consultant, check how they handle data definitions, security, validation against existing reports, ownership and post-launch support.
How does AI agent reporting work start, and how long does it take?
It starts with a free 30-minute scoping call; the duration depends on the data and requirements. Discovery clarifies the decisions and rules, then the data layer is prepared before the dashboard or agent is built. Handover covers how to use and maintain the work, followed by 30-day hypercare after launch. Scoping establishes the steps and timing for your specific setup.
How much do AI agents for reporting cost?
The cost depends on the number and condition of data sources, the models and business rules needed, refresh requirements, expected users, and the handover and support required. An agent that needs carefully defined interface actions may need more modeling and validation than a simple reporting workflow. A fixed quote comes after a short scoping call, once the work and its dependencies are clear.