{"record":{"id":"4606675ae98ff613","repo":"langchain-ai/langchain","slug":"got-invalid-json-object-error-e","errorCode":null,"errorMessage":"Got invalid JSON object. Error: {e}","messagePattern":"Got invalid JSON object\\. Error: (.+?)","errorType":"exception","errorClass":"OutputParserException","httpStatus":null,"severity":"error","filePath":"libs/core/langchain_core/utils/json.py","lineNumber":216,"sourceCode":"\n    Checks that it contains the expected keys.\n\n    Args:\n        text: The Markdown string.\n        expected_keys: The expected keys in the JSON string.\n\n    Returns:\n        The parsed JSON object as a Python dictionary.\n\n    Raises:\n        OutputParserException: If the JSON string is invalid or does not contain\n            the expected keys.\n    \"\"\"\n    try:\n        json_obj = parse_json_markdown(text)\n    except json.JSONDecodeError as e:\n        msg = f\"Got invalid JSON object. Error: {e}\"\n        raise OutputParserException(msg) from e\n    if not isinstance(json_obj, dict):\n        error_message = (\n            f\"Expected JSON object (dict), but got: {type(json_obj).__name__}. \"\n        )\n        raise OutputParserException(error_message, llm_output=text)\n\n    for key in expected_keys:\n        if key not in json_obj:\n            msg = (\n                f\"Got invalid return object. Expected key `{key}` \"\n                f\"to be present, but got {json_obj}\"\n            )\n            raise OutputParserException(msg)\n    return json_obj\n","sourceCodeStart":198,"sourceCodeEnd":231,"githubUrl":"https://github.com/langchain-ai/langchain/blob/e32fa9a52eab3b61ad7a45399bfde59b3e580fc4/libs/core/langchain_core/utils/json.py#L198-L231","documentation":"Error \"Got invalid JSON object. Error: {e}\" thrown in langchain-ai/langchain.","triggerScenarios":"Raised when parsing partial/malformed JSON output from a model fails even after best-effort repair, i.e. the text is not valid JSON.","commonSituations":"See trigger scenarios.","solutions":["Fix the malformed JSON emitted by the model (unbalanced braces/brackets or trailing text); parse_and_check_json_markdown expects valid JSON inside markdown code blocks.","Ensure the completion contains a fenced code block (```json ... ```) with a complete JSON value."],"exampleFix":"text = '```json\\n{\"a\": 1}\\n```'  # complete, balanced JSON","handlingStrategy":null,"validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"e32fa9a52eab3b61ad7a45399bfde59b3e580fc4","analyzedAt":"2026-08-14T18:42:09.092Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}