jd-opensource/joyagent-jdgenie · error · AgentParsingError
Error in code parsing
Error message
Error in code parsing:
{e}
Make sure to provide correct code blobs. What it means
smolagents-style CodeAgent raises AgentParsingError in _step_stream when parsing the LLM output into a code action fails. fix_final_answer_code(parse_code_blobs(output_text)) throws (e.g. no code blob found or post-processing error), and the raw exception is wrapped with a hint to provide correct code blobs.
Solutions
- Inspect the logged model output_text and adjust the prompt/system template so the model always emits a fenced code blob
- Catch AgentParsingError and re-prompt the model asking it to wrap its code in ```code``` fences
- Verify parse_code_blobs regex settings (or custom parsing provider) match the fencing style your model produces
- Check fix_final_answer_code for brittle assumptions and guard it against empty/None extracted code
Example fix
# before run(agent, "What is 2+2?") # model answers "2+2 is 4" -> AgentParsingError # after run(agent, "What is 2+2? Always provide your final answer inside a ```code``` block.")
Defensive patterns
Strategy: validation
Validate before calling
import re
def has_code_blob(text: str) -> bool:
return bool(re.search(r'```(?:\w+)?\s*[\s\S]+?\s*```', text or ''))
# call agent only if has_code_blob(model_output) else re-prompt Type guard
def is_valid_action(text):
return isinstance(text, str) and '```' in text Try / catch
from smolagents import AgentParsingError
try:
result = agent.run(prompt)
except AgentParsingError as e:
result = agent.run(prompt + "\nIMPORTANT: answer with a ```code``` block.") Prevention
- Always instruct the model to emit fenced ```code``` blocks
- Log raw output_text before parsing for debugging
- Pin model/version known to follow the code format
- Add a re-prompt fallback on AgentParsingError
When it happens
Trigger: The model output passed to parse_code_blobs contains no fenced code block (```...```) or malformed markup, or fix_final_answer_code throws on the extracted code. Any exception inside the try block at ci_agent.py:141 is converted to this error.
Common situations: LLM answers in prose or JSON instead of a code blob; model uses unusual fencing like ```python with unbalanced backticks; prompt/template changes make the model skip the code format; fix_final_answer_code regexes fail on newer model output styles.
Understand the failure class
Background: "Invalid JSON response" and "Failed to parse response" errors: when an API answers 200 but the body isn't the JSON your library expected — this error's family across 28 libraries.
Related errors
- Error in generating model output
- 解析llm json结果失败
- Tool execution failed: " + error
- Tool execution result is null
- Empty or invalid response from LLM
AI-assisted analysis of jd-opensource/joyagent-jdgenie@2417e0b8b6 (2026-09-08).
Data as JSON: /api/errors/69b6708d431c81c7.
Report an issue: GitHub.
Appendix: source
Thrown at genie-tool/genie_tool/tool/ci_agent.py:143
except Exception as e:
raise AgentGenerationError(
f"Error in generating model output:\n{e}", self.logger
) from e
self.logger.log_markdown(
content=output_text,
title="Output message of the LLM:",
level=LogLevel.DEBUG,
)
# Parse
try:
code_action = fix_final_answer_code(parse_code_blobs(output_text))
except Exception as e:
error_msg = (
f"Error in code parsing:\n{e}\nMake sure to provide correct code blobs."
)
raise AgentParsingError(error_msg, self.logger)
memory_step.tool_calls = [
ToolCall(
name="python_interpreter",
arguments=code_action,
id=f"call_{len(self.memory.steps)}",
)
]
# Execute
self.logger.log_code(
title="Executing parsed code:", content=code_action, level=LogLevel.INFO
)
try:
_, execution_logs, _ = self.python_executor(code_action)
# This put call was missing awaitView on GitHub (pinned to 2417e0b8b6)