{"record":{"id":"5a09390451c5bf16","repo":"langchain-ai/langchain","slug":"could-not-parse-function-call-data-exc","errorCode":null,"errorMessage":"Could not parse function call data: {exc}","messagePattern":"Could not parse function call data: (.+?)","errorType":"exception","errorClass":"OutputParserException","httpStatus":null,"severity":"error","filePath":"libs/core/langchain_core/output_parsers/openai_functions.py","lineNumber":128,"sourceCode":"                try:\n                    if self.args_only:\n                        return parse_partial_json(\n                            function_call[\"arguments\"], strict=self.strict\n                        )\n                    return {\n                        **function_call,\n                        \"arguments\": parse_partial_json(\n                            function_call[\"arguments\"], strict=self.strict\n                        ),\n                    }\n                except json.JSONDecodeError:\n                    return None\n            elif self.args_only:\n                try:\n                    return json.loads(function_call[\"arguments\"], strict=self.strict)\n                except (json.JSONDecodeError, TypeError) as exc:\n                    msg = f\"Could not parse function call data: {exc}\"\n                    raise OutputParserException(msg) from exc\n            else:\n                try:\n                    return {\n                        **function_call,\n                        \"arguments\": json.loads(\n                            function_call[\"arguments\"], strict=self.strict\n                        ),\n                    }\n                except (json.JSONDecodeError, TypeError) as exc:\n                    msg = f\"Could not parse function call data: {exc}\"\n                    raise OutputParserException(msg) from exc\n        except KeyError:\n            return None\n\n    # This method would be called by the default implementation of `parse_result`\n    # but we're overriding that method so it's not needed.\n    def parse(self, text: str) -> Any:\n        \"\"\"Parse the output of an LLM call to a JSON object.","sourceCodeStart":110,"sourceCodeEnd":146,"githubUrl":"https://github.com/langchain-ai/langchain/blob/e32fa9a52eab3b61ad7a45399bfde59b3e580fc4/libs/core/langchain_core/output_parsers/openai_functions.py#L110-L146","documentation":"Raised by JsonOutputFunctionsParser when args_only=True and the function-call 'arguments' string fails json.loads with JSONDecodeError or TypeError. The model produced a function call but its arguments were not valid JSON (or were not a string at all), so the parser cannot decode them.","triggerScenarios":"Model emits malformed JSON in function_call.arguments (unquoted keys, trailing commas, truncated output due to max_tokens); arguments is None (TypeError path); strict=True rejecting otherwise-acceptable output with control characters/newlines.","commonSituations":"Low max_tokens cutting off the JSON mid-string; models that emit Python-style dicts rather than JSON; setting strict=True while the model inserts raw newlines in strings.","solutions":["Increase max_tokens so the function call is not truncated","Set strict=False on the parser to tolerate non-JSON-compliant strings (control characters, newlines)","Catch OutputParserException and retry the call or repair the JSON (e.g. via a JSON-repair step) before parsing"],"exampleFix":"# before\nparser = JsonOutputFunctionsParser(args_only=True, strict=True)\n\n# after\nparser = JsonOutputFunctionsParser(args_only=True, strict=False)  # tolerate newlines/control chars","handlingStrategy":"try-catch","validationCode":"import json\nargs = result[0].message.additional_kwargs[\"function_call\"][\"arguments\"]\ntry:\n    json.loads(args)\nexcept json.JSONDecodeError:\n    ...  # repair or retry before invoking parser","typeGuard":null,"tryCatchPattern":"from langchain_core.exceptions import OutputParserException\ntry:\n    parsed = parser.parse_result(result)\nexcept OutputParserException as e:\n    # e.g. log raw arguments and retry with higher max_tokens\n    logger.warning(\"function args invalid JSON: %s\", e)","preventionTips":["Set strict=False to tolerate non-JSON-compliant strings","Give the model enough max_tokens to finish the JSON"],"tags":["openai-functions","output-parsing","json"],"backgroundTag":null,"analyzedSha":"e32fa9a52eab3b61ad7a45399bfde59b3e580fc4","analyzedAt":"2026-08-14T18:42:09.092Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}