PageIndex icon indicating copy to clipboard operation
PageIndex copied to clipboard

Fix invalid JSON formatting in LLM prompts causing KeyErrors

Open Himanshuwagh opened this issue 7 months ago • 2 comments

Several LLM prompts in page_index.py define a JSON structure for the model to follow but are missing commas between keys (specifically after the "thinking" key).

When the LLM follows these instructions literally, it produces invalid JSON. This causes the extract_json function to fail or return an empty dictionary, leading to KeyError exceptions when the code attempts to access keys like toc_detected, completed, or page_index_given_in_toc.

The following lines in pageindex/page_index.py are missing a trailing comma after the "thinking" value placeholder:

Line 34: inside check_title_appearance Line 62: inside check_title_appearance_in_start Line 112: inside toc_detector_single_page Line 132: inside check_if_toc_extraction_is_complete Line 150: inside check_if_toc_transformation_is_complete Line 213: inside detect_page_index

Himanshuwagh avatar May 06 '26 03:05 Himanshuwagh

fixed it in this pull request https://github.com/VectifyAI/PageIndex/pull/258

Himanshuwagh avatar May 06 '26 03:05 Himanshuwagh

Thanks for the report. Closing because the affected legacy JSON/Markdown/TOC path has since been replaced or covered by later parser validation, cleanup, retry, and error-handling changes. If this still reproduces on the latest release, please open a new issue with the input shape, model/provider, package version, and a minimal traceback.

BukeLy avatar Aug 31 '26 04:08 BukeLy