{"record":{"id":"69b6708d431c81c7","repo":"jd-opensource/joyagent-jdgenie","slug":"error-in-code-parsing-e-make-sure-to-provide-co","errorCode":null,"errorMessage":"Error in code parsing:\n{e}\nMake sure to provide correct code blobs.","messagePattern":"Error in code parsing:\n(.+?)\nMake sure to provide correct code blobs\\.","errorType":"exception","errorClass":"AgentParsingError","httpStatus":null,"severity":"error","filePath":"genie-tool/genie_tool/tool/ci_agent.py","lineNumber":143,"sourceCode":"        except Exception as e:\n            raise AgentGenerationError(\n                f\"Error in generating model output:\\n{e}\", self.logger\n            ) from e\n\n        self.logger.log_markdown(\n            content=output_text,\n            title=\"Output message of the LLM:\",\n            level=LogLevel.DEBUG,\n        )\n\n        # Parse\n        try:\n            code_action = fix_final_answer_code(parse_code_blobs(output_text))\n        except Exception as e:\n            error_msg = (\n                f\"Error in code parsing:\\n{e}\\nMake sure to provide correct code blobs.\"\n            )\n            raise AgentParsingError(error_msg, self.logger)\n\n        memory_step.tool_calls = [\n            ToolCall(\n                name=\"python_interpreter\",\n                arguments=code_action,\n                id=f\"call_{len(self.memory.steps)}\",\n            )\n        ]\n\n        # Execute\n        self.logger.log_code(\n            title=\"Executing parsed code:\", content=code_action, level=LogLevel.INFO\n        )\n\n        try:\n            _, execution_logs, _ = self.python_executor(code_action)\n\n            # This put call was missing await","sourceCodeStart":125,"sourceCodeEnd":161,"githubUrl":"https://github.com/jd-opensource/joyagent-jdgenie/blob/2417e0b8b636d941ad5fb14c59b20dddfef5375d/genie-tool/genie_tool/tool/ci_agent.py#L125-L161","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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"],"exampleFix":"# before\nrun(agent, \"What is 2+2?\")  # model answers \"2+2 is 4\" -> AgentParsingError\n# after\nrun(agent, \"What is 2+2? Always provide your final answer inside a ```code``` block.\")","handlingStrategy":"validation","validationCode":"import re\ndef has_code_blob(text: str) -> bool:\n    return bool(re.search(r'```(?:\\w+)?\\s*[\\s\\S]+?\\s*```', text or ''))\n# call agent only if has_code_blob(model_output) else re-prompt","typeGuard":"def is_valid_action(text):\n    return isinstance(text, str) and '```' in text","tryCatchPattern":"from smolagents import AgentParsingError\ntry:\n    result = agent.run(prompt)\nexcept AgentParsingError as e:\n    result = agent.run(prompt + \"\\nIMPORTANT: answer with a ```code``` block.\")","preventionTips":["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"],"tags":["llm","parsing","agent"],"backgroundTag":"invalid-json-response","analyzedSha":"2417e0b8b636d941ad5fb14c59b20dddfef5375d","analyzedAt":"2026-09-08T11:28:19.414Z","contentChangedAt":"2026-09-08T11:28:19.414Z","schemaVersion":2},"datasetVersion":"2026-09-16T09:17:16.951Z"}