{"record":{"id":"2b2b22097d23d40c","repo":"huggingface/smolagents","slug":"the-model-output-does-not-contain-any-json-blob","errorCode":null,"errorMessage":"The model output does not contain any JSON blob.","messagePattern":"The model output does not contain any JSON blob\\.","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"src/smolagents/utils.py","lineNumber":175,"sourceCode":"        return {str(k): make_json_serializable(v) for k, v in obj.items()}\n    elif hasattr(obj, \"__dict__\"):\n        # For custom objects, convert their __dict__ to a serializable format\n        return {\"_type\": obj.__class__.__name__, **{k: make_json_serializable(v) for k, v in obj.__dict__.items()}}\n    else:\n        # For any other type, convert to string\n        return str(obj)\n\n\ndef parse_json_blob(json_blob: str) -> tuple[dict[str, str], str]:\n    \"Extracts the JSON blob from the input and returns the JSON data and the rest of the input.\"\n    try:\n        first_accolade_index = json_blob.find(\"{\")\n        last_accolade_index = [a.start() for a in list(re.finditer(\"}\", json_blob))][-1]\n        json_str = json_blob[first_accolade_index : last_accolade_index + 1]\n        json_data = json.loads(json_str, strict=False)\n        return json_data, json_blob[:first_accolade_index]\n    except IndexError:\n        raise ValueError(\"The model output does not contain any JSON blob.\")\n    except json.JSONDecodeError as e:\n        place = e.pos\n        if json_blob[place - 1 : place + 2] == \"},\\n\":\n            raise ValueError(\n                \"JSON is invalid: you probably tried to provide multiple tool calls in one action. PROVIDE ONLY ONE TOOL CALL.\"\n            )\n        raise ValueError(\n            f\"The JSON blob you used is invalid due to the following error: {e}.\\n\"\n            f\"JSON blob was: {json_blob}, decoding failed on that specific part of the blob:\\n\"\n            f\"'{json_blob[place - 4 : place + 5]}'.\"\n        )\n\n\ndef extract_code_from_text(text: str, code_block_tags: tuple[str, str]) -> str | None:\n    \"\"\"Extract code from the LLM's output.\"\"\"\n    pattern = rf\"{code_block_tags[0]}(.*?){code_block_tags[1]}\"\n    matches = re.findall(pattern, text, re.DOTALL)\n    if matches:","sourceCodeStart":157,"sourceCodeEnd":193,"githubUrl":"https://github.com/huggingface/smolagents/blob/30bb1161095dbae2271e6bc3cc4c219cc3897a57/src/smolagents/utils.py#L157-L193","documentation":"parse_json_blob extracts the substring between the first '{' and the last '}' of model output and json.loads it. If no '{' or '}' exists, indexing/slicing raises IndexError, which is converted to this ValueError: the model produced no JSON at all.","triggerScenarios":"A ToolCallingAgent model reply containing only prose/thoughts with no JSON object; get_tool_call_from_text receiving chatty output without braces; empty or whitespace model responses.","commonSituations":"Weak or misconfigured chat models that ignore the tool-calling JSON format; truncated responses from timeouts or max-token limits; wrong prompt template for the model type.","solutions":["Retry the step so the model regenerates a proper JSON action","Use a stronger model or one of the built-in prompt templates suited to the model","Increase max_tokens / fix truncation so full JSON is emitted","Wrap agent.run steps with error handling and feed the error back as an observation so the agent self-corrects"],"exampleFix":"# before\naction = '{\"name\": \"search\", ...'  # truncated by max_tokens\n\n# after\nmodel = OpenAIServerModel(model_id='...', max_tokens=2000)\nagent.run(task)","handlingStrategy":"retry","validationCode":"def has_json_blob(text: str) -> bool:\n    return '{' in text and '}' in text","typeGuard":"def looks_like_action(text: str) -> bool:\n    import re\n    return bool(re.search(r'\\{.*\\}', text, re.DOTALL))","tryCatchPattern":"try:\n    data, pre = parse_json_blob(text)\nexcept ValueError as e:\n    if 'does not contain any JSON blob' in str(e):\n        # feed error back as observation and re-run the model step\n        raise","preventionTips":["Use models/templates that reliably emit JSON actions","Set sufficient max_tokens to avoid truncation","Enable retry/error-feedback in the agent loop"],"tags":["smolagents","llm-output-parsing","json","model-output"],"backgroundTag":"invalid-model-json-output","analyzedSha":"30bb1161095dbae2271e6bc3cc4c219cc3897a57","analyzedAt":"2026-08-28T18:52:54.169Z","schemaVersion":2},"datasetVersion":"2026-08-28T21:17:43.275Z"}