{"record":{"id":"1fd9b2c6e4a36fa2","repo":"iflytek/astron-agent","slug":"json-action-input-raw","errorCode":null,"errorMessage":"无效的插件参数JSON格式: {action_input_raw}","messagePattern":"无效的插件参数JSON格式: (.+?)","errorType":"exception","errorClass":"CotFormatIncorrectExc","httpStatus":null,"severity":"warning","filePath":"core/agent/engine/nodes/cot/cot_runner.py","lineNumber":144,"sourceCode":"\n    async def create_user_prompt(self) -> str:\n        user_prompt = COT_USER_TEMPLATE.replace(\n            \"{chat_history}\", await self.create_history_prompt()\n        )\n        user_prompt = user_prompt.replace(\"{question}\", self.question)\n        return user_prompt\n\n    async def _parse_action_input(self, action_input_raw: str) -> dict[str, Any]:\n        \"\"\"解析并验证 action_input JSON 格式\"\"\"\n        normalized_input = action_input_raw.strip()\n        normalized_input = re.sub(\n            r\"^```(?:json)?\\s*\", \"\", normalized_input, flags=re.IGNORECASE\n        )\n        normalized_input = re.sub(r\"\\s*```$\", \"\", normalized_input)\n        try:\n            return json.loads(normalized_input)\n        except json.decoder.JSONDecodeError:\n            raise cot_exc.CotFormatIncorrectExc(\n                f\"无效的插件参数JSON格式: {action_input_raw}\"\n            )\n\n    @staticmethod\n    def _find_marker(step_content: str, marker: str) -> Match[str] | None:\n        return PROTOCOL_MARKERS[marker].search(step_content)\n\n    def _has_complete_action(self, step_content: str) -> bool:\n        action = self._find_marker(step_content, \"action\")\n        action_input = self._find_marker(step_content, \"action_input\")\n        return bool(action and action_input and action.end() <= action_input.start())\n\n    def _extract_final_answer(self, step_content: str) -> str | None:\n        marker = self._find_marker(step_content, \"final_answer\")\n        if marker is None:\n            return None\n        return step_content[marker.end() :]\n","sourceCodeStart":126,"sourceCodeEnd":162,"githubUrl":"https://github.com/iflytek/astron-agent/blob/5e758547a83371a5a4b29dadf4ac03e8dd527635/core/agent/engine/nodes/cot/cot_runner.py#L126-L162","documentation":"In the CoT (chain-of-thought) agent runner, _parse_action_input parses the Action Input block of an LLM step as JSON. When json.loads fails after stripping optional ``` fences, it raises CotFormatIncorrectExc '无效的插件参数JSON格式' (invalid plugin-parameter JSON format) including the raw input. This enforces the ReAct-style protocol where Action Input must be a JSON object/string the plugin dispatcher can use.","triggerScenarios":"The LLM emits an Action Input block that is not valid JSON: unquoted keys, single quotes, trailing commas, Python-style dict repr, or prose mixed into the block.","commonSituations":"Weak/small models ignoring the JSON instruction; temperature too high causing malformed arguments; prompt template drift so the model mirrors examples with non-JSON syntax; multi-line strings without escaping.","solutions":["Strengthen the system prompt with explicit JSON-only examples for Action Input and few-shot correct outputs.","Lower model temperature or use JSON mode/function-calling if the model supports it, so arguments are schema-constrained.","Add a retry loop: catch CotFormatIncorrectExc and re-prompt the model with the validation error appended.","Optionally pre-sanitize common issues (trailing commas, single->double quotes) before json.loads in a fork."],"exampleFix":"// before (model output)\nAction Input: {'query': 'weather'}\n// after (prompt-enforced)\nAction Input: {\"query\": \"weather\"}","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try:\n    step = await runner.parse_cot_step(content)\nexcept CotFormatIncorrectExc as e:\n    if \"JSON\" in str(e):\n        content = sanitize_json_args(content)  # fix quotes/commas, then retry\n    raise","preventionTips":["Use JSON mode / function calling when the model supports it.","Include explicit JSON examples in the Action Input prompt section.","Lower temperature for tool-call steps.","Retry once with the parse error fed back to the model."],"tags":["llm","cot","json-parse-error","agent"],"backgroundTag":"invalid-json-response","analyzedSha":"5e758547a83371a5a4b29dadf4ac03e8dd527635","analyzedAt":"2026-09-12T08:03:51.356Z","contentChangedAt":"2026-09-12T08:03:51.356Z","schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}