Checking LLM Answers Against Tool Results Without Blowing Up Context
Published

How do you keep a cheap, fast grounding check reliable when the evidence it has to read keeps growing?
The setup#
Say you’re building an assistant that answers questions about a patient’s medications. It has tools like get_medications, and it calls them as needed to answer things like “what is this patient currently taking?”.
Because this kind of assistant is one hallucinated detail away from misleading a clinician, suggesting conflicting medications, or affecting a patient’s treatment, every response needs a grounding guardrail: a check that verifies the assistant’s answer is actually backed by the tool results it was given. To run that check on every single turn without tanking latency or cost, the natural choice is a small, fast model like Anthropic Claude Haiku. Not the frontier model generating the answer itself.
That works fine at first. The trouble starts as sessions get longer. More tool calls, more paginated results, more history and the evidence grows well past what a small model can reliably reason over in one pass.
The problem: splitting evidence breaks multi-fact answers#
The first instinct is to split the evidence into chunks and check each one in parallel. Each chunk gets checked independently, and the verdicts get combined at the end.
This has a problem: if a response is grounded by two different facts that happen to live in two different chunks, each chunk only ever sees half the picture. For example:
“[…] this patient is currently taking medication A for blood pressure and medication B for cholesterol.”
Medication A’s record lives in one page of tool results; medication B’s lives in another. If the guardrail checks each chunk against the whole response, chunk 1 only ever confirms half of it, chunk 2 only confirms the other half. A naive logic like “every chunk must fully confirm the response” fails the whole thing, even though the two chunks together fully support it.
- User questionWhat is this patient taking?
- Call get_medicationsTool results arrive in separate pages.
- Page 1Medication APage 2Medication B
- Assistant responseThe patient is taking medication A and medication B.
- Each check gets the whole answer but only its own pageChunk 1 checkConfirms medication A only.Chunk 2 checkConfirms medication B only.
- Naive reduce: rejectNeither chunk confirms the complete answer on its own.
We built and tested five approaches to this problem, using Strands agents on Amazon Bedrock with Claude Haiku 4.5 as the judge model, and ran each one against 32 synthetic test cases.
The approaches#
The code snippets below show the structure of each approach; parallel execution and implementation details are omitted.
A. Per-claim map, code reduce#
First, one LLM call breaks the response into atomic claims. Each chunk then gets the full claim list but only its own slice of evidence. Instead of returning one verdict for the whole response, the judge model returns a verdict per claim: supported, contradicted, or not_addressed. A plain code reduce step then combines the per-claim verdicts across chunks. No extra LLM call.
- Assistant responseThe answer to verify.
- Extract atomic claimsOne model call creates the shared claim list.
- Parallel checks · full claim list + local evidenceJudge chunk 1Supported, contradicted, or not_addressed per claim.Judge chunk 2Supported, contradicted, or not_addressed per claim.
- Combine labels in codeFor each claim: at least one support, no contradiction.
- Final verdictGrounded only if every claim passes.
def verify_response(response, evidence_chunks):
claims = extract_claims(response) # one LLM call: list of atomic claims
votes = {claim: [] for claim in claims}
for chunk in evidence_chunks: # run in parallel
chunk_verdicts = judge_model.run(
PER_CLAIM_PROMPT, claims=claims, evidence=chunk
) # -> {claim: "supported" | "contradicted" | "not_addressed"}
for claim, verdict in chunk_verdicts.items():
votes[claim].append(verdict)
# a claim is grounded if ANY chunk supports it and NONE contradict it
grounded = {
claim: "contradicted" not in v and "supported" in v
for claim, v in votes.items()
}
return all(grounded.values())
A claim is grounded if any chunk supports it and none contradict it. So evidence for medication A and evidence for medication B can live in different chunks and still both count.
Pros
Tied with B as the fastest of the five (5.9s avg). All judge calls run in parallel, and the reduce step is plain code with no extra LLM call.
Cons
Its misses come in two shapes. The first is a claim that depends on finding or assembling evidence within a very large record set, such as a single fact among 1,500 encounter records. Each chunk only votes on the slice it can see, so when no single chunk holds enough of the picture, the OR-reduce comes up empty even though the response is correct. The second is a later record that cancels or replaces an earlier one by ID only. That chunk looks unrelated on its own, so it votes not_addressed, and the OR-reduce keeps the earlier “supported”.
B. Extractive map, single reduce#
Each chunk doesn’t render a verdict at all. It extracts relevant quotes and reasoning. All extractions get concatenated, and one final call makes the actual judgment call over the combined evidence.
- Assistant responseShared with every extraction call.
- Parallel extraction · one evidence slice per callExtract from chunk 1Relevant quotes and reasoning; no verdict.Extract from chunk 2Relevant quotes and reasoning; no verdict.
- Concatenate extractionsPlain code gathers the evidence into one context.
- Single final judgeReads the answer and all extracted evidence.
- Final verdictOne grounding decision.
def verify_response(response, evidence_chunks):
extractions = [
judge_model.run(EXTRACT_PROMPT, response=response, evidence=chunk)
for chunk in evidence_chunks # run in parallel, no verdict yet
]
combined_evidence = "\n".join(extractions)
verdict = judge_model.run(
FINAL_JUDGMENT_PROMPT, response=response, evidence=combined_evidence
)
return verdict.is_grounded
Pros
Its single final reduce call sees every chunk’s extracted evidence at once, so it can assemble claims that span chunks. It’s also one of only two approaches to pass the hardest long-range case in the set: a 150-point noisy lab trend spread across 44 tool-result pages.
Cons
Unlike approach A, where the judge labels each claim as supported, contradicted, or not_addressed, B’s extractions are free-form, so nothing in them separates “not covered by this chunk” from “disputed by this chunk”. That shows up as silence being read as a problem: in one case, B rejected a correct response because the extracted evidence had no medication names, and concluded the claims could not be supported.
It also doesn’t fully escape the problem it was meant to solve. The final call reads every chunk’s extraction at once, so as responses carry more claims and evidence spreads across more chunks, that single call grows with them. That puts the small judge model back where the article started: reasoning over more context than it can reliably handle in one pass.
C. Code-executing agent#
Instead of reading the tool results as raw text, an agent queries them with code. It has exactly one tool: run arbitrary Python against the real tool-result data, which is already loaded in a sandbox as ordinary variables (lists, dicts, tables). For each claim in the response, the agent writes a small snippet, such as filtering rows, counting items, or cross-referencing two fields. The sandbox runs it, and only the short printed output goes back to the agent, so the raw data never enters the model’s context. Once it has checked everything, the agent writes a plain-text summary of what it found, and that summary is all the final judge call ever sees.
- Assistant responseThe claims the agent must verify.Full tool-result datasetLoaded as variables in the sandbox.
- Query loopAgent ↔ Python sandboxThe agent writes code. Python queries the full dataset and returns short printed results.Repeat as needed within the step budget
- Plain-text evidence summaryThe agent summarizes what it checked.
- Final judgeReads the answer and the summary.
- Final verdictOne grounding decision.
def verify_response(response, tool_results):
agent = Agent(
tools=[run_python_against(tool_results)],
system_prompt=CODE_AGENT_SYSTEM_PROMPT,
)
summary = agent.run(
f"Verify every claim in this response against the underlying data:\n{response}"
)
verdict = judge_model.run(
FINAL_JUDGMENT_PROMPT, response=response, evidence=summary
)
return verdict.is_grounded
Pros
The lowest input-token count of the five (~5,884 avg), and on the four production-scale test cases, roughly 4.5–25× fewer input tokens than the next-cheapest approach.
It never splits the evidence: the code runs against the entire dataset at once, so medication A on page 1 and medication B on page 2 are just two rows in the same Python object. Because it queries the data instead of reading it, its cost follows how much exploration a claim needs rather than how much data exists. That’s also why it handles the 150-point lab trend case, which breaks three of the other four approaches (A, D and E).
Cons
Slower than A and B. Each step in the agent loop is a full round trip: the model writes a snippet, the sandbox runs it, and the model reads the output before deciding what to check next, and those steps can’t run in parallel. More importantly, it only verifies what it decides to query. Its misses are the cases where a later record invalidates an earlier one by ID, date or snapshot: the agent confirms the medication in the medication list and never queries the other tool’s data, where the cancellation lives. Its step budget is also a design risk: a claim that needs a long, many-step investigation could run out of steps before the agent has the full picture.
D. Embedding-retrieval evidence selection#
Instead of splitting tool data into arbitrary sequential chunks, embed the response’s claims and the tool-result data, then retrieve only the top_k most relevant spans per claim before verification. This targets the split-fact problem head-on: retrieval can pull both medication A’s span and medication B’s span into the same evidence set for a single claim, regardless of where they originally sat.
- Assistant responseThe answer to verify.Tool-result recordsAll available evidence.
- Extract atomic claimsCreate one list of factual claims.Embed and indexPrepare searchable evidence once per turn.
- Retrieve top-k spans per claimSelected spans can cross page boundaries.
- One check per claimJudge claim 1Read its retrieved evidence.Judge claim 2Read its retrieved evidence.
- Combine claim verdictsGrounded only if every claim is supported.
def verify_response(response, tool_results):
claims = extract_claims(response)
index = build_embedding_index(tool_results) # chunk + embed once per turn
grounded = {}
for claim in claims:
relevant_spans = index.search(claim, top_k=3) # can cross chunk boundaries
verdict = judge_model.run(
PER_CLAIM_PROMPT, claim=claim, evidence=relevant_spans
)
grounded[claim] = verdict.is_supported
return all(grounded.values())
Pros
Works well for claims that rest on a few specific facts, and has the lowest output-token cost of the five (~564 avg), since each per-claim call returns one short verdict.
Cons
75% accuracy, and its main limitation is choosing k. Claims draw on very different amounts of evidence, and a fixed k, or even a similarity threshold, can’t adapt to that: too small and claims that span many records can’t be verified, too large and the judge wades through irrelevant spans. It also makes by far the most calls of any approach (367.4 on average), because it embeds every record separately, which keeps its latency (11.9s) well above A and B.
E. Refine / iterative sequential chain#
Process chunks one at a time, carrying forward a running verdict that gets revised, not just OR’d, as each new chunk arrives. Closer to the “refine” pattern used in iterative summarization than to classic map-reduce. This targets approach A’s mechanical-OR blind spot, since a later chunk can walk back an earlier chunk’s incorrect “supported” verdict instead of only ever adding to it.
- Assistant responseThe answer to verify.
- Extract atomic claimsOne model call creates the claim list.
- Initialize per-claim labelsEvery claim starts as not_addressed.
- Sequential · one chunk after anotherRefine the running verdictRead the next chunk with the previous labels. Revise each claim as new evidence arrives.Carry revised labels into the next step
- Final verdictGrounded only if every final label is supported.
def verify_response(response, evidence_chunks):
claims = extract_claims(response) # one LLM call: list of atomic claims
running_verdict = {claim: "not_addressed" for claim in claims}
for chunk in evidence_chunks: # sequential, not parallel
running_verdict = judge_model.run(
REFINE_PROMPT,
claims=claims,
evidence=chunk,
previous_verdict=running_verdict,
) # can upgrade OR downgrade any claim's verdict
return all(v == "supported" for v in running_verdict.values())
Pros
Its running verdict can walk back an earlier “supported” when a later chunk changes the picture, which a mechanical OR-reduce cannot do. We saw this happen: a later note discontinued “the medication started on 2026-01-10” without naming it, and E downgraded the claim that A’s OR-reduce kept as supported. And unlike D, its call count doesn’t scale with record count: it processes one chunk per call regardless of how many records that chunk contains.
Cons
75% accuracy, one case more than A, which isn’t enough to call it more accurate. The running verdict carries forward per-claim labels rather than the evidence behind them, so claims that need many records seen together stay out of reach, and so do invalidations that only make sense next to the earlier record’s details. It’s also the slowest and most input-heavy approach of the five (18.0s avg, ~23,759 input tokens), since each refine call depends on the last and none can run in parallel.
What we measured#
We ran a 160-run sweep (32 test cases × 5 approaches). The test cases include a category where a later record invalidates an earlier one using only an ID, date or snapshot, such as an order cancelled by order number, a superseded prescription, a medication list that turns out to be an archived snapshot, or vitals from a previous encounter.
All bars start at zero. Scales: accuracy 0–100%; latency 0–20 s; input tokens 0–25,000.
View all benchmark values, including output tokens
| Approach | Accuracy | Latency | Input tokens | Output tokens |
|---|---|---|---|---|
| A: Per-claim map, code reduce | 72% | 5.9 s | ~22,622 | ~2,716 |
| B: Extractive map, single reduce | 81% | 6.0 s | ~18,183 | ~812 |
| C: Code-executing agent | 84% | 8.6 s | ~5,884 | ~775 |
| D: Embedding retrieval | 75% | 11.9 s | ~19,614 | ~564 |
| E: Refine sequential chain | 75% | 18.0 s | ~23,759 | ~2,426 |
In Conclusion#
The split-fact scenario we started with turned out to be a good first test: all five approaches handle it once they stop judging each chunk in isolation. The experiments pointed to two harder problems. The first is claims that have to be assembled from a large evidence set rather than confirmed by one localized fact, where the approaches differ most in accuracy and in cost. The second is records that invalidate earlier ones by reference only. Three of those cases, a cancelled order, a superseded prescription, and an archived snapshot, were missed by all five approaches.
- A (per-claim map, code reduce) is tied for fastest. It works well when each claim can be confirmed by a fact within a single chunk, and breaks when evidence is spread across a large record set or when a later record invalidates an earlier one by ID only.
- B (extractive map, single reduce) is tied for fastest and can assemble claims that span chunks, because one final call sees all the extracted evidence. Its free-form extractions can read silence as a problem, and that final call grows as the evidence does.
- C (code-executing agent) uses the fewest input tokens by a wide margin, especially on the largest cases, because it queries the data instead of reading it. It only verifies what it chooses to query, so it can miss invalidations that live in another tool’s data, and its step budget limits how far it can explore.
- D (embedding retrieval) works well for claims that rest on a few facts and has the lowest output-token cost. Its weakness is choosing k: a fixed window, even with thresholding, can’t adapt to how much evidence each claim needs. It also makes by far the most calls.
- E (refine) can walk back an earlier “supported” verdict when a later chunk changes the picture. But it carries labels forward rather than evidence, and it’s the slowest and most input-heavy approach of the five.
No approach wins on every axis, so here’s what we’d pick. For grounding checks over large tool results, the code-executing agent is the best value of the five: the highest accuracy in our tests, on par with B, at a fraction of the input tokens, roughly 4.5–25× fewer than the next-cheapest approach on the largest cases. It comes with two limitations. It’s slower than A and B (8.6s against 5.9–6.0s), and it only checks what it decides to query, so it can miss a cancellation or a superseded record that lives in another tool’s data. If latency matters most and your claims usually rest on facts within a single page of results, the per-claim map (A) or the extractive map (B) are fast, simpler alternatives. And if your data has records that invalidate others by reference only, none of these approaches is enough on its own yet.
If you’ve built something similar, tried a different chunking strategy or reduce logic, or taken a completely different route, we’d like to hear about it. Email Guilherme.
References#
- RAG Faithfulness — definition and measurement, Deepchecks
- Ragas metrics explained: faithfulness and claim decomposition, Saulius Šlekys
- Self-Correcting RAG: Enhancing Faithfulness via MMKP Context Selection and NLI-Guided MCTS, arXiv:2604.10734
- HalluciNot: Hallucination Detection Through Context and Common Knowledge Verification, arXiv:2504.07069
- VISTA: Verification In Sequential Turn-based Assessment, arXiv:2510.27052
- awesome-hallucination-detection, EdinburghNLP — curated list of hallucination-detection research
- Summarization with LangChain — Stuff, Map-Reduce, Refine, Abonia Sojasingarayar — background on the refine-chain pattern behind Approach E
Tags
Topics