openhuman icon indicating copy to clipboard operation
openhuman copied to clipboard

[codex] fix numeric grounding in agent prompts

Open samrusani opened this issue 5 months ago • 1 comments

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 #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

  • [x] 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.
  • [x] Diff coverage ≥ 80% — changed lines are covered by focused Rust prompt tests; full merged diff-cover runs in CI.
  • [x] Coverage matrix updated — N/A: shared prompt-contract change, no feature row added/removed/renamed.
  • [x] All affected feature IDs from the matrix are listed in the PR description under ## Related — N/A: no matrix feature IDs affected.
  • [x] No new external network dependencies introduced (mock backend used per Testing Strategy).
  • [x] Manual smoke checklist updated if this touches release-cut surfaces (docs/RELEASE-MANUAL-SMOKE.md) — N/A: no release-cut manual smoke surface changed.
  • [x] 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

  • Closes: Closes #3603
  • Follow-up PR(s)/TODOs: N/A

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

  • [x] pnpm --filter openhuman-app format:check
  • [x] pnpm typecheck
  • [x] Focused tests: cargo test --manifest-path Cargo.toml openhuman::agent::prompts::tests -- --nocapture
  • [x] Rust fmt/check (if changed): cargo fmt --manifest-path Cargo.toml --all --check; cargo check --manifest-path Cargo.toml
  • [x] 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.

samrusani avatar Jun 15 '26 06:06 samrusani

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 27739ee59e649653cd5f2430ab44de22a726baa1 and 4512d962f95e2161805816db258f4a064c9afabd.

📒 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.

coderabbitai[bot] avatar Jun 15 '26 06:06 coderabbitai[bot]