{"record":{"id":"fc0897eb6df0431d","repo":"agentscope-ai/agentscope","slug":"system-reminder-error-message-your-argument-st","errorCode":null,"errorMessage":"<system-reminder>{error_message}\n\nYour argument string is decoded by the following code snippet{ellipsis_hint}:\n```python\nimport json\n\nyour_tool_arguments = {repr(error_json_str)}\njson.loads(your_tool_arguments)\n```\n\n**You should recorrect the arguments in JSON format.**</system-reminder>","messagePattern":"<system-reminder>(.+?)\n\nYour argument string is decoded by the following code snippet(.+?):\n```python\nimport json\n\nyour_tool_arguments = (.+?)\njson\\.loads\\(your_tool_arguments\\)\n```\n\n\\*\\*You should recorrect the arguments in JSON format\\.\\*\\*</system-reminder>","errorType":"exception","errorClass":"ToolJSONDecodeError","httpStatus":null,"severity":"error","filePath":"src/agentscope/_utils/_common.py","lineNumber":152,"sourceCode":"\n    except Exception:\n        # Whatever the error is, we throw the original error message to the\n        # agent, which is more helpful for debugging.\n        pass\n\n    # If still failed, we throw the original error message to the agent, rather\n    # than the error from json_repair, which is less helpful for debugging.\n    if len(json_str) > 200:\n        error_json_str = json_str[:100] + \"[TRUNCATE]\" + json_str[-100:]\n        ellipsis_hint = (\n            \"(Because the JSON string is too long, a truncated label \"\n            '\"[TRUNCATE]\" is used here to indicate the truncation)'\n        )\n    else:\n        error_json_str = json_str\n        ellipsis_hint = \"\"\n\n    raise ToolJSONDecodeError(\n        f\"\"\"<system-reminder>{error_message}\n\nYour argument string is decoded by the following code snippet{ellipsis_hint}:\n```python\nimport json\n\nyour_tool_arguments = {repr(error_json_str)}\njson.loads(your_tool_arguments)\n```\n\n**You should recorrect the arguments in JSON format.**</system-reminder>\"\"\",\n    )\n\n\ndef _get_timestamp(add_random_suffix: bool = False) -> str:\n    \"\"\"Get the current timestamp in the format YYYY-MM-DD HH:MM:SS.sss.\"\"\"\n    timestamp = datetime.now().strftime(\"%Y-%m-%d %H:%M:%S.%f\")[:-3]\n","sourceCodeStart":134,"sourceCodeEnd":170,"githubUrl":"https://github.com/agentscope-ai/agentscope/blob/e90f1c7592896cc95f6e5ee506194f533378247d/src/agentscope/_utils/_common.py#L134-L170","documentation":"When an agent emits tool-call arguments as a malformed or truncated JSON string, agentscope attempts a repair (_json_loads_with_repair). If repair fails, it raises ToolJSONDecodeError with a <system-reminder> prompt that is meant to be fed back to the LLM so it re-emits valid JSON arguments. This is an intentional error-feedback loop for structured tool calling.","triggerScenarios":"A model returns tool arguments with unescaped quotes/newlines, single quotes instead of double quotes, or output truncated at max length (the message then includes the '\"[TRUNCATE]\"' hint). Calling the internal JSON repair path with such a string triggers this exception.","commonSituations":"Weaker or smaller models producing non-strict JSON, long tool arguments hitting token limits causing truncation, nested quotes in string values, or non-ASCII/unescaped characters. Frequently seen with function-calling on models not fine-tuned for strict JSON.","solutions":["Catch ToolJSONDecodeError and send the error message (the <system-reminder> text) back to the model so it corrects the arguments","Reduce tool argument size (fewer/shorter parameters) to avoid truncation; increase the model's max output tokens","Switch to a model with stronger native function-calling/JSON mode","Simplify the tool schema — fewer required fields, shorter enums/descriptions"],"exampleFix":"# before\ntool_args = json.loads(msg.get_tool_args())  # raises raw JSONDecodeError\n\n# after\nfrom agentscope.exception import ToolJSONDecodeError\ntry:\n    tool_args = json.loads(msg.get_tool_args())\nexcept (ToolJSONDecodeError, json.JSONDecodeError) as e:\n    # feed the reminder back to the agent for correction\n    await agent.observe(Msg(\"system\", str(e), role=\"system\"))\n    msg = await agent.reply()","handlingStrategy":"retry","validationCode":"def try_parse_tool_args(raw: str) -> dict | None:\n    try:\n        return json.loads(raw)\n    except json.JSONDecodeError:\n        return None\n\nargs = try_parse_tool_args(msg.get_tool_args())\nif args is None:\n    # ask the model to re-emit instead of letting the pipeline raise\n    ...","typeGuard":"import json\nfrom typing import TypeGuard, Any\n\ndef is_valid_tool_args(raw: str) -> TypeGuard[str]:\n    try:\n        json.loads(raw)\n        return True\n    except json.JSONDecodeError:\n        return False","tryCatchPattern":"from agentscope.exception import ToolJSONDecodeError\n\ntry:\n    result = json.loads(tool_args_str)\nexcept ToolJSONDecodeError as e:\n    # e's message is designed to be shown back to the model\n    await agent.observe(Msg(\"system\", str(e), role=\"system\"))\n    corrected = await agent.reply()\n    result = json.loads(corrected.get_tool_args())","preventionTips":["Keep tool argument payloads small to avoid truncation-induced invalid JSON","Prefer models with native function calling / JSON mode","Always have a correction loop: catch the error and re-prompt rather than crashing the run","Validate JSON before dispatching to tool implementation"],"tags":["json","llm","tool-calling","model-output","repair"],"backgroundTag":"llm-invalid-json-output","analyzedSha":"e90f1c7592896cc95f6e5ee506194f533378247d","analyzedAt":"2026-08-28T18:24:12.087Z","schemaVersion":2},"datasetVersion":"2026-08-28T21:17:43.275Z"}