{"record":{"id":"a6f045df0597c9d1","repo":"langchain-ai/langchain","slug":"got-invalid-return-object-expected-key-key-to","errorCode":null,"errorMessage":"Got invalid return object. Expected key `{key}` to be present, but got {json_obj}","messagePattern":"Got invalid return object\\. Expected key `(.+?)` to be present, but got (.+?)","errorType":"exception","errorClass":"OutputParserException","httpStatus":null,"severity":"error","filePath":"libs/core/langchain_core/utils/json.py","lineNumber":229,"sourceCode":"    \"\"\"\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":211,"sourceCodeEnd":231,"githubUrl":"https://github.com/langchain-ai/langchain/blob/e32fa9a52eab3b61ad7a45399bfde59b3e580fc4/libs/core/langchain_core/utils/json.py#L211-L231","documentation":"Error \"Got invalid return object. Expected key `{key}` to be present, but got {json_obj}\" thrown in langchain-ai/langchain.","triggerScenarios":"Raised when parsed JSON output lacks a required key that the caller explicitly demanded (e.g. an 'action'/'action_input' key).","commonSituations":"See trigger scenarios.","solutions":["Ensure the parsed JSON object contains the expected key exactly as named (check spelling and nesting).","Adjust the expected_keys argument to match the keys the model actually returns."],"exampleFix":"parse_and_check_json_markdown(text, expected_keys=['action', 'action_input'])","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-15T17:31:12.345Z"}