Support copilot keeps repeating dead SQL tool calls
Summary
On one tenant a missing-column error sends the agent into five near-identical retries, burning 19k tokens in a single turn. I'm tracing the loops in Braintrust and weighing whether tenant-specific schema mocks for evals are worth it.
What the comments say
A missing-column error is deterministic, so retrying with tweaked SQL can't fix it; cap identical failures at two, then return the real column list for that tenant and end the turn.
Control belongs in the tool runner, not the prompt: fingerprint each call by tool plus normalized args (literals stripped), and on a second identical failure return a structured "blocked this session" result instead of the raw DB error.
Passing raw Postgres errors invites alias and quoting tweaks; catching error 42703 and returning "Column X does not exist. Available columns: [A, B, C]" usually fixes it on the next call.
Don't hand-maintain tenant mocks: pull each tenant's column list from the information schema at turn start or cache it daily, put it in the tool description, and reuse the same snapshot in evals.
A per-tenant daily cost alert answers "how often does this happen" without tracing every turn, and a sqlglot AST check in the wrapper can reject missing columns before the query reaches the database.
Join the discussion
Was this useful to you?
Related
How do you make AI agents reliable when they use multiple tools?
r/AI_Agents · Aware-Resource9831
LLM as a judge in production: ship it in shadow mode first
prasad.tech
Can public chat data predict real-world AI misalignments?
openai.com
The Filter Was in the Question: Grounding Agent Queries Before the First SQL
shyanming.substack.com · Shown, Not Claimed
AI vs human sales: week 3 ends 0 to 500,000 ₽, and the 30,000 ₽ ad budget is still untouched
vc.ru · ИИ продаёт против человека