Skip to content

Harden LLM deserialization and fallback handling#90

Open
lethanhson9901 wants to merge 1 commit intosopaco:mainfrom
lethanhson9901:fix/llm-deserialize-fallbacks
Open

Harden LLM deserialization and fallback handling#90
lethanhson9901 wants to merge 1 commit intosopaco:mainfrom
lethanhson9901:fix/llm-deserialize-fallbacks

Conversation

@lethanhson9901
Copy link
Contributor

Summary

This PR improves resilience when model outputs do not strictly match expected schemas during documentation generation.

It addresses failures like:

  • Failed to deserialize ... missing field 'name'
  • Failed to deserialize ... missing field 'responsibilities'
  • Similar missing/loose field issues in AI analysis outputs

Root Cause

Some LLM responses are schema-unstable (missing required fields, variant naming drift, mixed value shapes such as object/string/array), while parts of the pipeline previously required strict deserialization.

Changes

  • Hardened deserialization for code insight structures with lenient parsing and defaults.
  • Added tolerant mapping for CodePurpose from raw/variant text.
  • Added robust parsing for AI code-purpose analysis fields (code_purpose, confidence, reasoning).
  • Added fallback behavior in code insight analysis:
    • if AI extraction fails, return static-analysis insight instead of failing the whole run.
  • Added #[serde(default)]/Default handling for key report structures to avoid hard failures on partial outputs.
  • Added Mermaid safety constraints to relevant compose prompts to reduce invalid Mermaid syntax generation.

Tests

  • cargo test passed (53 passed, 0 failed).
  • cargo check passed.
  • Verification repeated in a clean temporary worktree with only this patch applied.

Scope / Out of Scope

  • Scope is intentionally limited to deserialization robustness, fallback safety, and Mermaid prompt hardening.
  • Large unrelated local workspace changes were intentionally excluded to keep this PR safe and reviewable.

Impact

  • Prevents pipeline interruption from non-critical LLM schema variance.
  • Preserves documentation generation continuity by degrading gracefully to static analysis when needed.
  • Improves output reliability without changing core workflow intent.

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.

1 participant