fix: improve JSON extraction and TOC fallback handling#333
Open
KairosMarco wants to merge 1 commit into
Open
Conversation
Author
|
Hi maintainers, I wanted to check whether this scope is aligned with the project direction. The PR is focused on JSON response resilience and TOC fallback handling, with unittest coverage. If this is too broad, I am happy to split it into a smaller parser-only PR first, then a separate TOC fallback PR. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This PR improves PageIndex robustness when LLM calls return JSON in common non-ideal formats or omit optional fields during TOC/page-index extraction.
It keeps the existing indexing flow unchanged, but adds safer parsing and fallback behavior for provider responses that include:
physical_indexvalues.Why
While running PageIndex over a FinanceBench PDF subset, I saw indexing failures from model response shape issues such as:
The failures were not specific to one document format; they came from LLM JSON formatting variance.
Changes
extract_json()tolerate fenced JSON, embedded JSON, arrays, trailing text, and Python-style literal tokens.list[dict]before list operations.Processing failedafter fallback attempts.unittestcoverage for the JSON parser and TOC fallback helpers.Validation
Local result:
I also validated equivalent fixes in a local benchmark workspace:
The benchmark artifacts are available here:
https://github.com/KairosMarco/pageindex-benchlab