Skip to content

fix(agentic_rag): normalize structure answers - #19025

Merged
yingfeng merged 1 commit into
infiniflow:mainfrom
yzl0ng:fix/structure-answer-coercion
Aug 31, 2026
Merged

yingfeng merged 1 commit into
infiniflow:mainfrom
yzl0ng:fix/structure-answer-coercion

Conversation

@yzl0ng

@yzl0ng yzl0ng commented Aug 30, 2026

Copy link
Copy Markdown
Contributor

Summary

  • normalize a sufficient structure answer to text before trimming it
  • preserve the existing empty-answer behavior for missing or insufficient verdicts
  • add an async regression test for a valid JSON numeric answer

Problem

_ask_structure parses model output as arbitrary JSON but calls .strip() directly on verdict["answer"] after the protected parsing block. If the model returns a valid non-string JSON answer such as 42, the resulting AttributeError escapes and aborts the knowledge-graph/compiled-structure exploration turn instead of returning the answer and relevant entities.

This is a focused follow-up to the agentic search refactor in #19000.

Test plan

  • uv run --no-project --python 3.13 --with pytest --with pytest-asyncio --with json-repair pytest --confcutdir=test/unit_test/rag/advanced_rag test/unit_test/rag/advanced_rag/test_structure_qa.py -q
  • uvx ruff check test/unit_test/rag/advanced_rag/test_structure_qa.py
  • uvx ruff check --select E9,F63,F7,F82 rag/advanced_rag/harness/structure_qa.py
  • uvx ruff format --check rag/advanced_rag/harness/structure_qa.py test/unit_test/rag/advanced_rag/test_structure_qa.py

@dosubot dosubot Bot added size:XS This PR changes 0-9 lines, ignoring generated files. 🌈 python Pull requests that update Python code 🐞 bug Something isn't working, pull request that fix bug. 🧪 test Pull requests that update test cases. labels Aug 30, 2026
@coderabbitai

coderabbitai Bot commented Aug 30, 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 Plus

Run ID: dee4cc73-fbf8-471b-b70c-c252969b95ab

📥 Commits

Reviewing files that changed from the base of the PR and between a39b6ec and aaddb03.

📒 Files selected for processing (2)
  • rag/advanced_rag/harness/structure_qa.py
  • test/unit_test/rag/advanced_rag/test_structure_qa.py

Included review availability: Your plan provides up to 10 included reviews per hour; 8 remain after this review.


📝 Walkthrough

Walkthrough

The structure QA helper now handles missing, empty, and non-string answers explicitly. A new async unit test verifies numeric answer conversion and filtering of invalid relevant entities.

Changes

Structure answer normalization

Layer / File(s) Summary
Answer normalization and test coverage
rag/advanced_rag/harness/structure_qa.py, test/unit_test/rag/advanced_rag/test_structure_qa.py
_ask_structure converts non-null answers to trimmed strings without replacing empty strings. The test verifies numeric answer normalization and exclusion of numeric relevant entities.

Estimated code review effort: 2 (Simple) | ~10 minutes

Merge Risk: ⚪ Minimal · up to aaddb

The change prevents valid non-string structure answers from aborting exploration while preserving existing empty-answer handling. No actionable merge-blocking risk remains after normal checks and review.

Poem

A rabbit checks the answer string,
And keeps an empty value’s ring.
Numbers turn to "42" clear,
Invalid entities disappear.
Tests hop in with carrots bright.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 33.33% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 3 functions across 2 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description check ✅ Passed The description includes the required Summary section and clearly explains the purpose, problem, implementation, regression test, and validation commands.
Title check ✅ Passed The title clearly identifies the main change: normalizing structure answers in agentic RAG.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
  • Fix all pre-merge checks with AI

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.

@yingfeng yingfeng added the ci Continue Integration label Aug 31, 2026
@codecov

codecov Bot commented Aug 31, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 39.09%. Comparing base (a39b6ec) to head (aaddb03).
⚠️ Report is 3 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main   #19025      +/-   ##
==========================================
+ Coverage   30.43%   39.09%   +8.65%     
==========================================
  Files          54       54              
  Lines       14911    14911              
  Branches      117      117              
==========================================
+ Hits         4538     5829    +1291     
+ Misses      10361     9056    -1305     
- Partials       12       26      +14     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@yingfeng
yingfeng merged commit d7e453e into infiniflow:main Aug 31, 2026
15 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

🐞 bug Something isn't working, pull request that fix bug. ci Continue Integration 🌈 python Pull requests that update Python code size:XS This PR changes 0-9 lines, ignoring generated files. 🧪 test Pull requests that update test cases.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants