Before You Give an Agent Your API, Test What It Gets Back
An agent can use almost any API. Whether it answers correctly depends on what the response says and what the tools around it still claim.
Before you give an agent an existing API, capture what its tools send back and build a test around it. Can the agent justify its answer from what it received? How many calls, tokens and seconds does it take? A passing answer can hide a lucky guess. It can also hide a lookup the frontend already knows how to do.
The study in brief
API owners often want to give agents the same APIs their UIs use. I built a simulated bank desk to see what that does to the answers. The services were deterministic. A given call in a given setup always returned the same data, and each model chose which calls to make.
Three jobs, 17 fixtures.
- Brief from a saved query (9 fixtures). Report how many accounts across the book have an open review, or say the saved result can’t establish it. The fixtures vary whether delivery was complete, capped or unconfirmed, whether the SQL had a
LIMIT, whether the source list was already partial and whether a saved count was current or a day old. Two more cover pagination and a sign-off that authorizes a fresh count. - Refer a trade (4 fixtures). Report the sector’s projected share of exposure. Refer the Halden trade if it leaves that share above 22%.
- Book an approved trade (4 fixtures). Decide whether the credit-committee approval is current and belongs to this trade. It can be valid, pending, expired or for an earlier trade.
I tested six ways of presenting each task. I started with the original UI response. In three variants I kept that response and changed what the agent knew before it arrived, either by putting a warning in the prompt or tool description, or by preloading a field dictionary. In the other two I reshaped the response itself, once in a concise form and once with extra detail. I also tested specific changes to the sector dictionary, the value used for unknown coverage and the approval records.
Runs and scoring. Six models ran each of the 119 combinations 20 times, for 14,280 conversations. Every conversation started at the desk’s request, and the model chose its own tools through native function calling. A trial passed only with the right figures, the right decision and permitted evidence. A briefing, for example, could not run a fresh count. I also recorded calls, tokens, time and cost. A separate model-free checker flags any two records whose visible inputs match but whose required answers differ. A smaller pilot on Haiku alone started just after the first tool call.1
Two results set the tone for the rest. Warned that delivery can stop early, Luna withheld the total on every capped and unknown result, and on all 20 complete ones too. On the sector screen, Qwen divided a percentage by 100 twice in 44 of 80 decisions because I’d renamed the fields and left the old dictionary in place.
Three rows, two wrong answers
Birch, Elm and Fir are open for review. A desk wants a briefing from a saved query that returned those three accounts. How many accounts across the book have an open review?
I started with a pilot on Haiku 5.5. Each conversation began just after the tool call, with the executed SQL, the rows and a field called rows_returned already in context. On a result the service had capped at three rows, Haiku explained:
It returned three rows (Birch, Elm, Fir), and the query has no row limit, so the saved result establishes 3 open accounts.
Haiku had read the SQL correctly. There was no LIMIT. The service had stopped delivery at three, and the response didn’t say so.
In the full study, with a different prompt and Haiku choosing its first tool, it went the other way. It answered “unknown” all 60 times. That was right on every capped and inconclusive result. It was wrong on all 20 where the answer really was three.
The desk needed different answers in situations the original response made look identical. Guessing three happened to work when the list was complete. Withholding the total worked when the service had stopped early. The three names gave Haiku no way to tell which answer the desk could use.
What can three rows establish?
The desk asked for the current book-wide total if the saved result established it. The complete, capped and unknown cases all returned the same three names, the same unrestricted SQL and the same row count. In the complete case the desk should get three. In the other two it should get an unknown total. For a separate sign-off request, the desk authorized a fresh count against the capped result. There the count returned 19.
With a warning that delivery can stop early, in the prompt or the tool description, Haiku, Luna and Terra withheld the total on every briefing and failed every complete case. Coverage reported for the particular request got Luna to 60/60 and Terra to 58/60.
Can three saved rows establish a book-wide total?
Original response
Prompt warning
Tool-description warning
Preloaded dictionary
Coverage fields
Verbose response
With the coverage fields, the unknown result carried exhausted: null. Haiku read it and reported three accounts on 20/20 runs. The flags for freshness, source completeness and book-wide scope were all true. I changed only the exhaustion value to the string "unknown". Haiku then correctly withheld the total on 12/20 runs. Qwen also improved, from 6/20 to 14/20. Sonnet went from 8/20 to 12/20. Luna and Terra passed all 20 with either encoding. Gemini scored 0/20 on both under the first-result-only rule, even though it returned an unknown total on all 20 explicit-unknown runs.
I reran the null version later as a check. Haiku again said three on all 20 runs. Qwen passed 3/20.
Gemini Neon returned the right figures on 537 of 860 saved-result briefings. In 215 of those it also called next_page. Each call returned {"error": "no saved next page"}. The desk required Gemini to use the first result alone, so 322 briefings passed on both the figures and the tool use. On the sector and approval tasks, Gemini’s factual and full-task pass counts agreed.
A saved aggregate needs a clock as well as a scope. Two fixtures returned the same full-book count of 19. One count was taken at the desk’s requested time. The other was taken the day before, and the book had since grown to 23 open accounts. Both responses stated the counting time, the requested time and the scope. The desk allowed only the saved result, so the right answers were 19 and unknown. On the original response across six models, 102/120 fresh-count briefings and 109/120 stale-count briefings passed. A grader that accepts 19 for both rewards the wrong answer on yesterday’s count.
A check you can run on your own API
Take two service records that need different answers to the same request. Capture everything the consumer is allowed to see, including the tool descriptions, any preloaded context and any permitted follow-up responses. If those inputs match, you have a pair of examples no model can reliably tell apart.
My checker includes seven contrasts against a complete result. Delivery may have hit a cap, left another page or timed out. The source may be filtered, stale or already partial. The service may be unable to confirm it reached the end. I repeated those contrasts at row counts from one to 64. That produces 448 conflicting pairs with the original interface. The coverage renderer was written from the same state list, so zero collisions after adding its fields is an expected regression check. The more informative use is to run the checker on independently labelled records from your own service.
Agno had a real version of this bug. Its tool returned files from Google Drive but omitted the flag that says a search across drives was incomplete. Drive reports that separately from whether there is another page. GitHub search likewise reports when it runs out of time even if the matches it found happen to be all of them. The reproduction download includes small fixtures based on those contracts. Agno issue and fix · Google Drive file lists · GitHub search timeouts
The Halden trade and the old dictionary
Halden is a counterparty on the simulated FX desk. A proposed trade needs referral if Halden’s sector would account for more than 22% of exposure after the trade. One screen returned 2204, 2192 and 2200. Its dictionary identified the projected share, current share and threshold, all in basis points. The trade would move the sector from 21.92% to 22.04%, triggering a referral. The other fixtures landed exactly on the threshold, moved exposure back below it or left it above.
What the grid and dictionary tools returnedSix versions of the same two tools, with the payloads for trade H-814
The agent had two tools that took no arguments: read_grid() and dictionary(). It could call both in its first turn, before it had seen what the grid contained.
read_grid() returneddictionary() returnedread_grid() for trade H-814
Original screen: the values the frontend displays
{
"trade_id": "H-814",
"screen": "sector_control_v2",
"cells": {
"v1": 2204, "v2": 2192, "v3": 2200
}
}Named percentages: identical in the old-dictionary, updated-dictionary and no-dictionary versions
{
"trade_id": "H-814",
"sector_share_after_pct": 22.04,
"sector_share_before_pct": 21.92,
"referral_threshold_pct": 22.0
}dictionary()
Original, preloaded, old-dictionary and verbose versions: the screen’s mapping, in basis points
{
"v1": "sector share after the proposed trade, basis points",
"v2": "sector share before the trade, basis points",
"v3": "desk referral threshold, basis points"
}Updated-dictionary version: same tool name and description, describing the named fields
{
"sector_share_after_pct": "sector share after the proposed trade, percent",
"sector_share_before_pct": "sector share before the trade, percent",
"referral_threshold_pct": "desk referral threshold, percent"
}The named grid already answers the question: 22.04% exceeds 22.0%, so the trade needs referral. Applying the old basis-point mapping divides every value by 100 again. The comparison still holds, so the referral decision stays right, but the reported exposure becomes 0.2204%.
In the pilot, I gave each percentage a name and divided each value by 100. Both versions passed 12/12 trials. Follow-up calls fell from 16 to three. But the pilot had already put the grid into context. In the full study, Luna and Terra fetched the grid and its dictionary together on all 80 original trials each. They did the same when I changed the grid payload and left the lookup tool in place. By the time the named fields arrived, the models had already asked for a dictionary that described the old screen.
In one run, Qwen received a projected share of 21.91%, applied the old basis-point conversion and reported 0.2191%. It reached the correct referral decision with the wrong exposure. Across four trade fixtures, Qwen reported exactly one hundredth of the correct share 44 times in 80 trials with the old dictionary. I kept the named percentage payload fixed and tested two changes: update the dictionary to describe those fields, or remove the dictionary tool. The hundredfold error disappeared in both arms.
| What Qwen could see | Decisions passing | Cost per 1,000 decisions |
|---|---|---|
| Original screen, dictionary available | 65/80 | $1.31 |
| Original screen, dictionary preloaded | 73/80 | $0.93 |
| Named percentages, old dictionary available | 28/80 | $1.66 |
| Named percentages, raw screen and old dictionary together in the payload | 77/80 | $0.86 |
| Named percentages, updated dictionary available | 75/80 | $0.85 |
| Named percentages, dictionary tool removed | 79/80 | $0.57 |
The verbose response gave Qwen the original cells alongside their dictionary. Its 77 passes don’t say which addition helped. The fairer comparison uses the same percentage payload in all three versions. Qwen passed 28/80 with the old dictionary, 75/80 with the updated dictionary and 79/80 with the tool removed. Against the old dictionary, those gains were 59 and 64 percentage points (paired 95% bootstrap intervals of 48 to 70 and 54 to 74 points, respectively).
I also reran the old-dictionary baseline on all four fixtures. Qwen passed 34/80 on the repeat and made the hundredfold error 40 times, compared with 28 passes and 44 such errors originally. The cost of the same baseline moved from $1.66 to $1.54 per thousand decisions while median time moved from 2.88 to 3.51 seconds. Both dictionary fixes had lower observed costs than either baseline run. The fixes ran in a different batch from both Qwen baselines, so routing, caching and load could contribute to the cost and time differences.
The same percentage fields with three dictionary choices
Old dictionaryUpdated dictionaryNo dictionary tool
The old dictionary also put Luna at 75/80, Terra at 69/80 and Gemini at 57/80 with named percentages. All three reached 80/80 with the updated dictionary. Removing the tool put Terra and Gemini at 80 and Luna at 79. For this screen I’d ship the field mapping and its dictionary change together. Keeping the original screen and preloading its dictionary was also a credible option, especially if the frontend already supplies it.
Time and tokens for the same referral decision
Old dictionaryUpdated dictionaryNo dictionary tool
What the approvals screen already got right
A second Halden screen showed an “Approved” badge for an earlier trade. The original response included the trade ID for the badge, the authorization records and a legend for their status codes. Operations needed a current credit-committee approval for the exact trade it was about to book. Across the six models, the original response passed 119/120 valid approvals and 118/120 wrong-trade cases.
I tried two ways a transformation could go wrong. First I dropped the trade ID from each authorization record. A valid approval and one for the earlier trade now looked identical. On the valid trades, 115/120 answers refused to book and five gave no booking decision. On the wrong trades, 115/120 correctly refused and five gave no decision. Across these two cases there were zero instructions to book. Losing the ID blocked good trades.
Then I mapped the pending code to “approved.” This error went the other way. On the pending fixture, 119/120 answers said to book and one gave no booking decision. With the original screen, 116/120 correctly declined with the right reason. I’d keep the original approvals response. It already carried the evidence the booking decision depended on.
Before giving an agent a UI endpoint, I’d start with one real desk question and find two service states where it needs different answers. I’d compare what the agent can see in each. Then I’d give it the question and the tools it will have in production, and watch which ones it calls before the first response arrives.
Footnotes
-
The six-model study contains 14,280 conversations covering 714 model, case and response-shape combinations with 20 repetitions each. Models were Claude Haiku 5.5, Claude Sonnet 5.5, GPT-6 Luna, GPT-6.1 Terra, Gemini 4 Neon and Qwen3.8 27B. OpenRouter served Qwen. The other five models used their native APIs. Each conversation allowed up to six model turns, a requested temperature of 1 and 2,048 output tokens per turn. The services and data were synthetic. The main study was collected in two batches: 7,761 trials in the first and 6,519 in the second. For Qwen, the original null and string trials came from different batches. For Haiku, six null trials came from the first batch and 14 from the second, which also tested the string. A separate 600-conversation replication repeated the four old-dictionary sector fixtures and the null-exhaustion fixture on all six models. The tables, charts and intervals describe the main study; the replication results appear in the text. Comparisons span collection batches and include network and API latency. Confidence intervals describe repeat variation on these fixtures. The pilot started after the first call and used a different prompt and harness, so the change in Haiku’s behavior cannot be attributed to start time alone. Download the fixtures, checker, runner, recorded trials and analysis (ZIP). ↩