Skip to content

fix: add type checks to prevent AttributeError when LLM returns malformed JSON#210

Open
octo-patch wants to merge 1 commit intoVectifyAI:mainfrom
octo-patch:fix/issue-199-type-check-malformed-json
Open

fix: add type checks to prevent AttributeError when LLM returns malformed JSON#210
octo-patch wants to merge 1 commit intoVectifyAI:mainfrom
octo-patch:fix/issue-199-type-check-malformed-json

Conversation

@octo-patch
Copy link
Copy Markdown

Fixes #199

Problem

When the LLM returns malformed JSON, extract_json() in utils.py returns {} (empty dict) as a fallback. This causes two crashes downstream:

Crash 1: AttributeError: 'dict' object has no attribute 'extend' in process_no_toc

  • generate_toc_init() can return {} on parse failure
  • Calling .extend() on a dict raises AttributeError

Crash 2: AttributeError: 'str' object has no attribute 'get' in meta_processor

  • When LLM returns a list of strings instead of dicts, iterating and calling .get() fails

Solution

Added minimal type guards at the two crash sites:

  1. process_no_toc: Check that generate_toc_init() returns a list before using it. Skip non-list results from generate_toc_continue() rather than crashing.

  2. meta_processor: Added isinstance(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.

Copy link
Copy Markdown

@claude claude bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Claude Code Review

This pull request is from a fork — automated review is disabled. A repository maintainer can comment @claude review to run a one-time review.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

AttributeError crashes in meta_processor and process_no_toc when LLM returns malformed JSON

1 participant