fix(visualize): guard against invalid visual_genre crashing generation - #748
Open
wangzitiansky wants to merge 1 commit into
Open
fix(visualize): guard against invalid visual_genre crashing generation#748wangzitiansky wants to merge 1 commit into
wangzitiansky wants to merge 1 commit into
Conversation
The analysis LLM occasionally outputs visual_genre values outside the Literal allowlist (e.g. "simulation"), which causes Pydantic's model_validate to raise ValidationError and hard-fail the entire book generation pipeline. Two-layer defense: - Prompt: enumerate valid values in user_template_fixed (en + zh) so the LLM sees a hard boundary before generating. - Code: wrap model_validate with try/except in AnalysisAgent; on failure, degrade visual_genre to "" and retry — graceful fallback instead of crashing. Co-Authored-By: Claude <noreply@anthropic.com>
wangzitiansky
force-pushed
the
fix/visual-genre-fallback
branch
from
August 1, 2026 16:38
477c0c8 to
fb8b849
Compare
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.
Description
Problem: Book generation crashes when creating interactive visualization
blocks. The analysis LLM sometimes outputs a
visual_genrevalue outside theallowed list — for example,
"simulation"instead of"interactive":ValidationError: 1 validation error for VisualizationAnalysis
visual_genre
Input should be '', 'flowchart', 'structural', 'illustrative',
'chart', 'stepper', 'interactive', 'mockup' or 'art'
[type=literal_error, input_value='simulation', input_type=str]
Root cause: The
user_template_fixedprompt describedvisual_genrewithan open-ended phrase ("the genre that best fits..."), so the LLM never saw a
hard boundary on which values are actually allowed. Pydantic's
model_validatethen raised aValidationErrorwith no recovery path,hard-failing the entire pipeline.
Fix: Two-layer defense:
user_template_fixed(en + zh) so the LLM knows the boundary beforegenerating.
model_validatewith try/except inAnalysisAgent— on failure, degradevisual_genreto""and retry.The code generator already has an
"any other genre"catch-all branch,so empty string degrades gracefully instead of crashing.
Related Issues
Module(s) Affected
agentsapiconfigcoreknowledgeloggingservicestoolsutilsweb(Frontend)docs(Documentation)scriptstests...Checklist
pre-commit run --all-filesand fixed any issues.Additional Notes
Add any other context or screenshots about the pull request here.