Skip to content

fix(agent): flag invented amounts after a computation fails - #6818

Merged
kovtcharov-amd merged 1 commit into
amd:mainfrom
kovtcharov:fix/failed-computation-figures
Nov 6, 2026
Merged

kovtcharov-amd merged 1 commit into
amd:mainfrom
kovtcharov:fix/failed-computation-figures

Conversation

@kovtcharov

@kovtcharov kovtcharov commented Nov 6, 2026 •

Copy link
Copy Markdown
Contributor

Asked for net revenue by region from a 500-row CSV, Gemma 4 E4B on the NPU ran run_python, which failed on No module named 'pandas' and printed nothing. It then answered with a confident table: North $10,342.50, West $10,678.98, and so on. The real totals are about four times that (North $45,043.62), and none of the answer's figures was in any tool output. Nothing warned the user, for two reasons:

  • The table was never checked. The figure check only read bare numbers, so a cell written as $10,342.50 didn't count as a value and the whole table passed. Reading the CSV was not the hole: in a replay against a 500-row orders file, it didn't count as a source for these amounts. Now a currency sign in a cell is read like a bare number, so invented amounts get one correction and then the "not confirmed" note.
  • The failed run said nothing about figures. fix(agent): flag invented figures when a computation never ran #6791 added a "the computation did not run" note, but review limited it to denied runs. Now a run_python, execute_python_file or query_data call that fails before printing anything is told plainly that nothing was computed: don't report figures, fix it and run it again, or tell the user what's needed. A failing shell command, and a script that printed results before it crashed, still get no note.

Amounts a script did print still pass, in a table or in prose. This composes with #6771, which only changes the written-file check.

Eval categories to watch: gaia_honesty, plus data_analysis and file_ops, where answers put computed amounts in tables.

Not fixed here: the Python environment that run_python uses has no pandas, though models reach for it all the time. That's why this run failed in the first place. Shipping pandas there, or saying in the tool description that it's missing, would prevent most of these failures. That needs its own change.

🔍 Technical details
  • _PURE_VALUE in grounding.py now accepts an optional $, US$, C$, A$, €, £ or ¥ before the number. _cell_value's existing rule still applies, so $5 stays unjudged and $10,342.50 is judged.
  • _with_computation_note keeps COMPUTATION_NOT_RUN for denials. It adds COMPUTATION_FAILED when a script tool (SCRIPT_COMPUTATION_TOOLS, which leaves out run_shell_command) fails and has no stdout, result or rows. query_data reports errors as "Error: ..." strings, so the note is appended to the string.
  • The content row and a short paragraph in docs/sdk/core/agent-system.mdx describe both.

Test plan

  • pytest tests/unit/agents/test_grounding_unsourced_figures.py: the NPU turn, replayed with a scripted model (summary, pandas-less run_python failure, summary, read, invented table), now gets the failure note and the correction, and ships with the note naming 10,342.50. 6 of the new tests failed against main before the fix.
  • Same file: a printed-then-crashed script, a failing pytest, and a $ table that a script printed all get no note.
  • pytest tests/unit/agents tests/unit/test_file_tools.py with Lemonade unreachable
  • Re-ask the orders.csv question on Gemma 4 E4B (NPU) in the desktop app: the reply gives no figures, or carries the note. On the integration build Gemma gave no totals and said they were unverified. That run didn't attempt run_python, so the crashed-script path itself is covered by the unit tests only.

A run_python that failed on a missing pandas, then a table of invented
dollar totals, shipped with no warning: table cells written as "$10,342.50"
were never read as values, and the failed run said nothing about figures.
Currency-marked cells are now judged like bare numbers, and a script or
scratchpad query that fails before printing anything tells the model that
nothing was computed. Failing shell commands, and scripts that printed
results before crashing, still get no note.
@github-actions github-actions Bot added documentation Documentation changes tests Test changes agents labels Nov 6, 2026
@github-actions

github-actions Bot commented Nov 6, 2026

Copy link
Copy Markdown
Contributor

Verdict: Approve with suggestions

Two holes let a model show invented dollar figures with no warning: the figure check skipped table cells that start with a currency sign, and a script that crashed before printing anything didn't tell the model that nothing had been computed. This PR closes both, and the scope stays narrow. Shell commands and scripts that printed partial output still get no note, and amounts a script really printed still pass. One small gap remains: a negative amount written as -$1,234.56 still isn't read as a value.

Real-world evidence

N/A: no evidence bundle was produced for this run. The change is in the agent's internal grounding checks, with no CLI or API surface that this lane could exercise. The verdict rests on a static review and the PR's replayed-turn unit test. The PR's unchecked item, re-asking the orders.csv question on Gemma 4 E4B (NPU) in the desktop app, is still the real proof. It should be checked before or soon after merge, and gaia_honesty, data_analysis and file_ops should be watched on the next RC eval, since this changes what the model sees after a failed tool call.

🔍 Technical details

Issues

🟢 Negative currency amounts are still skipped (src/gaia/agents/base/grounding.py:414). The optional currency prefix sits before -?, so $-1,234.56 matches but the usual -$1,234.56 doesn't. An invented loss or refund in a table cell still passes unjudged. Allowing a sign before the currency covers it:

    r"^\s*\**\s*(-)?\s?(?:(?:US|C|A)?\$|€|£|¥)?\s?"

This needs the capture-group indices in _cell_value (lines 524–528) shifted and the sign reapplied. Alternatively, keep the regex and strip a leading - before the currency sign in _cell_value. Either way, add a -$… row to test_dollar_cells_in_a_table_are_presented_data.

🟢 String results only get the failure note, never the denial note (src/gaia/agents/base/agent.py:6984-6989). A JSON-encoded string result with status: denied gets neither note, because the denial check only runs on dicts. That matches the old behaviour, and every computation tool returns a dict or plain text today, so this is only worth a comment if that ever changes. No action needed.

Checked and fine

  • tool_result_failed matches query_data's "Error: …" and "Error executing query: …" strings through _PLAIN_ERROR_RE, and "Query returned no results." is correctly left alone.
  • {"status": "success", "return_code": 1} counts as failed through the non-zero return_code rule, so execute_python_file crashes with an empty stdout get the note.
  • The _PURE_VALUE change reaches only presented_values (table cells and CSV fields), which only the content check uses. The written-file check isn't affected, consistent with the PR's note about fix(agents): stop footering figures a script computed this turn #6771.
  • _cell_value's small-number rule still applies, so $5 stays unjudged.
  • Both the timed and untimed _execute_tool paths call _with_computation_note, so there is no sibling path missing the note.
  • The docs: the content row and the new paragraph in agent-system.mdx match the code. No other doc describes the old "denied only" behaviour.

Strengths

  • The regression test replays the exact failing NPU turn end to end (scripted tool calls, then the invented table) and asserts that the note reaches the model and the final answer.
  • Shell commands are deliberately left out (SCRIPT_COMPUTATION_TOOLS) and a partial stdout suppresses the note, which avoids nagging the model during ordinary fix-and-retry loops.
  • The two tests moved out of test_other_results_are_left_alone show the behaviour change explicitly instead of quietly dropping coverage.

@kovtcharov-amd kovtcharov-amd added this to the v0.25.4 milestone Nov 6, 2026
@kovtcharov-amd
kovtcharov-amd added this pull request to the merge queue Nov 6, 2026
Merged via the queue into amd:main with commit 23a2589 Nov 6, 2026
40 checks passed
@kovtcharov-amd
kovtcharov-amd deleted the fix/failed-computation-figures branch November 6, 2026 10:29
@github-actions github-actions Bot mentioned this pull request Nov 6, 2026
4 of 6 tasks
kovtcharov added a commit to kovtcharov/gaia that referenced this pull request Nov 6, 2026
amd#6831)

After `run_python` failed on a missing pandas, Gemma 4 E4B on the NPU
took the per-region `unit_price` sums from `analyze_data_file` and
divided them itself: "North: 2322.16 / 141 = **16.40748**" (it is
16.4692), with East and West wrong too. No note appeared, because a
plain decimal in prose was only checked beside a table or a dollar
amount. Now, when a Python or query computation was asked for this turn
and none succeeded, the answer's prose decimals are checked as well: a
wrong quotient is named in the "not confirmed" note, while a correct
division (South, 2429.44 / 125 = 19.43552) and numbers copied from tool
output pass.

Follows amd#6818. Eval category to watch: `gaia_honesty`.

## Test plan
- [x] `pytest tests/unit/agents/test_grounding_unsourced_figures.py`:
the exact Gemma answer is flagged for 16.40748, 18.08606 and 17.13675,
not 19.43552 or the sums; the scripted-loop replay ships it with the
note. Both failed before the fix.
- [x] Same file: correct averages after the failed run, and the same
answer after a successful run, get no note.
- [x] `pytest tests/unit/agents tests/unit/test_file_tools.py` with
Lemonade unreachable (one unrelated collection error: `amd-gaia` package
metadata missing on this machine)
- [ ] Replay in the app on Gemma NPU: average unit_price per region
after a failed run_python
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents documentation Documentation changes tests Test changes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants