Score Tool Call Arguments in LLM Evals: Exact Match vs AST
Score tool call arguments by parsing them and comparing typed fields. Exact match rejects correct calls; AST-style comparison grades what matters.
To score tool call arguments in LLM evals, don’t use exact match on the raw string. Use AST-style comparison: parse the call, then compare its typed fields against the gold answer. Exact match marks a correct call wrong over whitespace, key order or quoting. AST comparison grades only the parts that change what the tool does. Free-text fields that structure can’t settle go to a calibrated LLM judge.
The comment log of my approval-gated X growth agent looked healthy for weeks. Every line ended in a success, and no run raised an error. Four hardcoded target accounts in its list no longer existed, and they soaked up 88% of the daily comment attempts for about six weeks. The job wasn’t crashing. It was measuring activity, and the activity went nowhere. Tool call evals fail the same way: a check can pass every case while grading the wrong thing.
Why does exact match fail tool call arguments?
Two identical tool calls can serialize to different strings. {"city": "NYC", "days": 3} and {"days":3,"city":"NYC"} mean the same thing to any JSON consumer, but a string comparison calls them different.
JSON objects have no key order, models emit whatever whitespace they like, and a number can show up as 3 or 3.0. A string comparison can’t tell those harmless differences from a real error, like "Boston" where the gold answer says "NYC". So exact match produces two kinds of noise: false failures on correct calls, and no way to say which field was wrong.
Parsing fixes the first problem, but naive parsing has a trap of its own. In Python, True == 1 and 1 == 1.0, so a plain == on parsed objects will accept a boolean where the schema wants an integer. The comparison has to check types as well as values:
import json
def typed_equal(a, b):
if type(a) is not type(b): # True vs 1, 3 vs "3" fail here
return False
if isinstance(a, dict):
return a.keys() == b.keys() and all(typed_equal(a[k], b[k]) for k in a)
if isinstance(a, list):
return len(a) == len(b) and all(map(typed_equal, a, b))
return a == b
def score_call(pred_raw: str, gold: dict) -> bool:
try:
pred = json.loads(pred_raw)
except json.JSONDecodeError:
return False # unparseable is a failure, not a skip
return typed_equal(pred, gold)
My bot’s long-form article lane shows what a silent skip costs: it lost 8 of 20 generations to JSON parse errors, and each failure silently burned a 48-hour slot. A grader that skips unparseable output instead of failing it hides exactly that kind of loss.
Whether 3.0 should match a gold 3 is a schema decision, not a grader default. The sketch above rejects it, which is the strict choice. A team that accepts numeric widening should write that rule down explicitly. Normalise strings, such as trimming or case-folding, only for the fields where the schema says it is safe. Whitespace matters in paths, code and patterns.
Doesn’t AST comparison just mean parsing the JSON?
Mostly, yes. That’s the point. Parsing turns text into the tree the tool will actually execute. The word “AST” is looser here than it sounds. The Gorilla paper (2023) parses generated code and matches the sub-tree rooted at the API call. It uses that match to identify which API in its dataset the model called, and to flag calls to APIs that don’t exist (arXiv 2305.15334). The Berkeley Function Calling Leaderboard (2025) checks calls with an AST matcher against an answer key of acceptable values. The authors present that as a cheaper proxy for actually executing the function (ICML 2025, PMLR v267).
Both approaches make the same core move: compare structure, not surface text. Their limit is just as clear. Structure doesn’t settle string values. "NYC" and "New York City" have the same shape and different content, so a purely structural grader marks one of them wrong. That gap is real, and it’s why the grader needs a second layer for free-text fields, covered below. Validation and scoring are different jobs: a schema validator decides whether a call may run, while an eval grader decides whether it matches the right answer. Pydantic vs Zod for validating LLM tool call arguments covers the first.
Real gold answers are rarely a single object. A good AST-style answer key lists the acceptable values for each parameter, for example both “NYC” and “New York City”, and marks which optional parameters may be left out. The typed_equal sketch above requires identical keys, so as written it fails a correct call that omits an optional parameter. Extend it to check each predicted value against the list of acceptable values for that key, and to skip optional keys that are absent.
Isn’t strict exact match the safe choice for production evals?
It feels safe because it never gives credit for anything it can’t see. The costs it creates are real, though, and they land on the team, not on the grader.
The first cost is misattributed failure. Suppose, as illustrative arithmetic rather than a measured figure, that one correct call in five differs only by key order or whitespace. Across a 1,000-case suite, exact match records 200 false failures. Someone then rewrites the prompt to chase those 200 cases, and the prompt may get worse on the cases that were right all along. Where the gold answers come from matters as much as how you compare them; see synthetic vs real test cases for LLM agent evals.
The second cost is passing for the wrong reason. My comment job logged success on every run, and nothing in that signal could tell activity from results. Argument graders make the same mistake when they check only the tool name, or only that the call ran without error. The lesson from that job: a green log is evidence of activity, not correctness.
The third cost is benchmark error. Epoch AI’s 2026 review of the Berkeley leaderboard audited 50 randomly sampled items and found defects that could affect accuracy in at least 24 of them, or at least 48%. That’s why it rated the benchmark “Flawed” (Epoch AI review). When the grader or its answer key is that noisy, a two-point gap between models tells you very little.
Form is not truth, outside evals too. In Moffatt v. Air Canada (2024 BCCRT 149, dated 14 February 2024), a British Columbia tribunal held the airline liable for a website chatbot’s wrong statement about its bereavement fare policy and ordered an award of $812.02 (CBC). The answer was fluent and well formed, and it was wrong. A check on form alone would have passed it, which is the same blind spot a structure-only grader has with free-text arguments. That case involved a free-text answer, not a tool call, but the lesson carries over to free-text arguments.
Can an LLM judge replace the structural check?
No. A judge should handle only the residue that structure can’t settle, and its agreement with humans has to be measured first. UniToolCall (2026) combines rule-based matching with ROUGE-L semantic matching for argument values (arXiv 2604.11557).
A layered grader looks like this:
| Layer | Catches | Misses | Use it for |
|---|---|---|---|
| Exact string | Byte-identical output | Whitespace, key order, number formatting | Nothing as a sole grader |
| Parsed equality | Key order, whitespace | Type drift such as True vs 1 | Fast first pass |
| Typed structural compare | Wrong values, wrong types, missing keys | Equivalent string values | Enums, numbers, booleans, IDs |
| Judge against gold | Equivalent free text | Judge error, cost, drift | Free-text fields only, after calibration |
The judge layer needs the same care as any grader. The rubric problems in LLM judge scores every answer the same apply directly. LLM-as-a-judge reliability describes how to check the judge against human labels before you trust its verdicts.
Doesn’t better scoring just inflate the numbers?
It moves scores in both directions, which is the reason to do it. Typed comparison will credit some calls that exact match rejected. It will also fail some calls that exact match passed, and that second group is the one people tend to miss.
A well-formed call can still be one you shouldn’t allow. In July 2025, an AI coding agent on Replit deleted a production database during a code and action freeze. The company’s CEO apologized, and the agent later said it had panicked (Fortune). A grader that checked only that the delete call was well formed would have passed it. The eval has to ask whether the call was allowed in that state, which is a different question from whether its arguments parse. An IBM Research team studying agentic function calling in 2025 made a related point: a paraphrased request should produce the same invocation. Their TrustNLP paper found that models often fail that test, and that AST-style scoring can penalise valid variations of a correct call (arXiv 2504.00914).
The change in practice is simple to state. Parse every argument payload. Count anything unparseable as a failure. Compare typed fields against gold. Send only the free-text residue to a calibrated judge. Report each layer’s error rate separately, so you can see whether you’re losing cases to formatting or to real mistakes. An eval that scores structure honestly will show lower numbers for some prompts and higher numbers for others. The numbers worth trusting are the ones from a grader whose own error rate you have measured.