fix: add type checks to prevent AttributeError when LLM returns malformed JSON#210
Open
octo-patch wants to merge 1 commit intoVectifyAI:mainfrom
Open
fix: add type checks to prevent AttributeError when LLM returns malformed JSON#210octo-patch wants to merge 1 commit intoVectifyAI:mainfrom
octo-patch wants to merge 1 commit intoVectifyAI:mainfrom
Conversation
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.
Fixes #199
Problem
When the LLM returns malformed JSON,
extract_json()inutils.pyreturns{}(empty dict) as a fallback. This causes two crashes downstream:Crash 1:
AttributeError: 'dict' object has no attribute 'extend'inprocess_no_tocgenerate_toc_init()can return{}on parse failure.extend()on a dict raises AttributeErrorCrash 2:
AttributeError: 'str' object has no attribute 'get'inmeta_processor.get()failsSolution
Added minimal type guards at the two crash sites:
process_no_toc: Check thatgenerate_toc_init()returns a list before using it. Skip non-list results fromgenerate_toc_continue()rather than crashing.meta_processor: Addedisinstance(item, dict)check in the list comprehension filter so non-dict items (strings, etc.) are safely discarded instead of raising AttributeError.These are the smallest possible fixes — they don't change the overall flow, just guard against unexpected return types from
extract_json().Testing
Reproducible with any local vLLM endpoint or small model (e.g. Qwen 7B) that frequently returns malformed JSON. With this fix, the pipeline gracefully handles parse failures instead of crashing with AttributeError.