Skip to content

[codex] fix numeric grounding in agent prompts#3678

Merged
senamakel merged 1 commit into
tinyhumansai:mainfrom
samrusani:fix/numeric-tool-output-guardrails
Jun 16, 2026
Merged

[codex] fix numeric grounding in agent prompts#3678
senamakel merged 1 commit into
tinyhumansai:mainfrom
samrusani:fix/numeric-tool-output-guardrails

Conversation

@samrusani

@samrusani samrusani commented Jun 15, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Tighten the shared agent grounding contract so numeric evidence must be copied exactly from observed sources.
  • Cover counts, sizes, dates, timestamps, durations, currencies, percentages, quotas, and ids.
  • Add prompt regression coverage for the main dynamic prompt path and the narrow sub-agent renderer.

Problem

  • The agent can paraphrase, round, or recompute numerical claims after reading tool output.
  • That can produce wrong storage amounts, counts, durations, and dates even when the source data was available.
  • Issue Agent hallucinates numbers — storage, counts, durations #3603 explicitly allows a scoped system-prompt rule as a first fix for this failure mode.

Solution

  • Extend the existing central GROUNDING_BODY prompt contract instead of adding a separate post-processor.
  • Require exact preservation of numeric evidence from tool results, user messages, or cited memory.
  • Instruct agents not to round, convert units, rewrite relative times, or recalculate unless the user asks and the calculation is shown from observed values.
  • Assert the new contract is present in dynamic prompts and inherited by sub-agent prompts.

Submission Checklist

  • Tests added or updated (happy path + at least one failure / edge case) per Testing Strategy — added prompt regression coverage for exact numeric evidence and sub-agent inheritance.
  • Diff coverage ≥ 80% — changed lines are covered by focused Rust prompt tests; full merged diff-cover runs in CI.
  • Coverage matrix updated — N/A: shared prompt-contract change, no feature row added/removed/renamed.
  • All affected feature IDs from the matrix are listed in the PR description under ## Related — N/A: no matrix feature IDs affected.
  • No new external network dependencies introduced (mock backend used per Testing Strategy).
  • Manual smoke checklist updated if this touches release-cut surfaces (docs/RELEASE-MANUAL-SMOKE.md) — N/A: no release-cut manual smoke surface changed.
  • Linked issue closed via Closes #NNN in the ## Related section.

Impact

  • Runtime/platform impact: core agent prompt text only; no frontend, persistence, RPC, or migration changes.
  • Performance impact: negligible, two additional static grounding bullets in the system prompt.
  • Compatibility impact: sub-agents inherit the same numeric-grounding rule through the existing shared prompt constant.

Related


AI Authored PR Metadata (required for Codex/Linear PRs)

Linear Issue

  • Key: N/A, GitHub issue contribution.
  • URL: N/A, GitHub issue contribution.

Commit & Branch

  • Branch: fix/numeric-tool-output-guardrails
  • Commit SHA: 4512d962

Validation Run

  • pnpm --filter openhuman-app format:check
  • pnpm typecheck
  • Focused tests: cargo test --manifest-path Cargo.toml openhuman::agent::prompts::tests -- --nocapture
  • Rust fmt/check (if changed): cargo fmt --manifest-path Cargo.toml --all --check; cargo check --manifest-path Cargo.toml
  • Tauri fmt/check (if changed): pre-push hook ran cargo fmt --manifest-path app/src-tauri/Cargo.toml --all --check and cargo check --manifest-path app/src-tauri/Cargo.toml

Validation Blocked

  • command: N/A after setup.
  • error: N/A after setup. Local pre-push initially failed because app dependencies and vendored Tauri submodules were missing; resolved with pnpm install and git submodule update --init --recursive.
  • impact: Final push hooks passed. Local environment still warns that Node is v22.22.3 while the repo requests >=24.0.0.

Behavior Changes

  • Intended behavior change: agents are instructed to preserve numeric claims exactly from observed evidence instead of paraphrasing, rounding, unit-converting, or recomputing them by default.
  • User-visible effect: answers grounded in tool output should be less likely to misstate counts, sizes, timestamps, dates, durations, and quotas.

Parity Contract

  • Legacy behavior preserved: existing tool-use, anti-fabrication, action, and output-style grounding rules remain in the same shared prompt contract.
  • Guard/fallback/dispatch parity checks: tests assert the rule is appended through SystemPromptBuilder::build and the narrow sub-agent renderer.

Duplicate / Superseded PR Handling

  • Duplicate PR(s): None found for #3603 before publishing.
  • Canonical PR: This draft PR.
  • Resolution (closed/superseded/updated): N/A.

Summary by CodeRabbit

  • Bug Fixes

    • Enhanced numeric evidence handling to preserve exact values without rounding or unit conversion unless explicitly requested; conflicting numeric sources are now identified rather than resolved with approximations.
  • Tests

    • Added verification tests for numeric evidence preservation in system prompts.

@coderabbitai

coderabbitai Bot commented Jun 15, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: e7bb4c83-4417-47d7-982e-c69f0b2b87a8

📥 Commits

Reviewing files that changed from the base of the PR and between 27739ee and 4512d96.

📒 Files selected for processing (2)
  • src/openhuman/agent/prompts/mod_tests.rs
  • src/openhuman/agent/prompts/sections.rs

📝 Walkthrough

Walkthrough

Two lines are added to the GROUNDING_BODY constant in sections.rs, prohibiting numeric transformations (rounding, unit conversion, relative-time rewriting, recalculation) and requiring discrepancies to be named. Two tests in mod_tests.rs are added or extended to assert these new clauses appear in rendered prompts.

Changes

Numeric Evidence Grounding Contract

Layer / File(s) Summary
GROUNDING_BODY rule + test coverage
src/openhuman/agent/prompts/sections.rs, src/openhuman/agent/prompts/mod_tests.rs
GROUNDING_BODY gains two clauses requiring exact copying of numeric evidence and prohibiting transformations unless explicitly requested with shown calculations; a new unit test asserts the full clause text is present in a custom-final-body prompt, and an existing sub-agent workspace-tail test is extended with the same assertion.

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~3 minutes

Poem

A rabbit checked the numbers twice,
No rounding here — be precise!
Five-point-four-nine TB? A lie!
Quote the tool output, do not fudge or pry.
The grounding contract holds the line,
Exact numeric truth, by design. 🐇✨

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title '[codex] fix numeric grounding in agent prompts' clearly summarizes the main change: updating agent system prompts to fix numeric evidence handling.
Linked Issues check ✅ Passed The PR fully addresses issue #3603 by implementing strict numeric grounding rules in the system prompt to prevent agent hallucinations with numbers.
Out of Scope Changes check ✅ Passed All changes are scoped to agent prompts and tests; no frontend, persistence, RPC, or migration modifications are included.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@samrusani
samrusani marked this pull request as ready for review June 15, 2026 09:54
@samrusani
samrusani requested a review from a team June 15, 2026 09:54
@senamakel
senamakel merged commit a32f361 into tinyhumansai:main Jun 16, 2026
22 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Agent hallucinates numbers — storage, counts, durations

2 participants