[GH-ISSUE #42] Add defensive handling for LLM sanitizer responses #9

Closed
opened 2026-03-02 04:07:47 +03:00 by kerem · 1 comment
Owner

Originally created by @gadievron on GitHub (Dec 22, 2025).
Original GitHub issue: https://github.com/gadievron/raptor/issues/42

Problem

Lines 488-500 in packages/codeql/agent.py assume analysis.sanitizers attribute exists, but LLM can return various response types depending on Instructor configuration:

  • Dict (no attributes)
  • Pydantic model (with sanitizers)
  • Custom structure (may lack sanitizers)

When response structure differs, AttributeError occurs and breaks autonomous analysis vulnerability assessment.

Root Cause

Instructor library can return different response types based on model capabilities, schema complexity, and Pydantic configuration. Current code assumes Pydantic model with sanitizers attribute always exists.

Impact

  • Breaks autonomous analysis vulnerability assessment
  • Poor error handling for unexpected LLM responses
  • Fails ungracefully when structure differs

Fix

Add defensive attribute access:

# Use getattr with default
sanitizers = getattr(analysis, 'sanitizers', [])
if not sanitizers:
    logger.debug(f"No sanitizers found (type: {type(analysis).__name__})")

File: packages/codeql/agent.py:488-500

Type

  • Bug fix (defensive improvement)
  • Bug #4 from internal analysis
  • Multi-agent validated
Originally created by @gadievron on GitHub (Dec 22, 2025). Original GitHub issue: https://github.com/gadievron/raptor/issues/42 ## Problem Lines 488-500 in `packages/codeql/agent.py` assume `analysis.sanitizers` attribute exists, but LLM can return various response types depending on Instructor configuration: - Dict (no attributes) - Pydantic model (with sanitizers) - Custom structure (may lack sanitizers) When response structure differs, AttributeError occurs and breaks autonomous analysis vulnerability assessment. ## Root Cause Instructor library can return different response types based on model capabilities, schema complexity, and Pydantic configuration. Current code assumes Pydantic model with `sanitizers` attribute always exists. ## Impact - Breaks autonomous analysis vulnerability assessment - Poor error handling for unexpected LLM responses - Fails ungracefully when structure differs ## Fix Add defensive attribute access: ```python # Use getattr with default sanitizers = getattr(analysis, 'sanitizers', []) if not sanitizers: logger.debug(f"No sanitizers found (type: {type(analysis).__name__})") ``` **File:** `packages/codeql/agent.py:488-500` ## Type - Bug fix (defensive improvement) ## Related - Bug #4 from internal analysis - Multi-agent validated
kerem 2026-03-02 04:07:47 +03:00
Author
Owner

@gadievron commented on GitHub (Dec 22, 2025):

Fixed in PR #48

<!-- gh-comment-id:3684217162 --> @gadievron commented on GitHub (Dec 22, 2025): Fixed in PR #48
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/raptor#9
No description provided.