langchain-ai/langchain · error · OutputParserException

Could not parse function call data: {exc}

Error message

Could not parse function call data: {exc}

What it means

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.

Source

Thrown at libs/core/langchain_core/output_parsers/openai_functions.py:128

                try:
                    if self.args_only:
                        return parse_partial_json(
                            function_call["arguments"], strict=self.strict
                        )
                    return {
                        **function_call,
                        "arguments": parse_partial_json(
                            function_call["arguments"], strict=self.strict
                        ),
                    }
                except json.JSONDecodeError:
                    return None
            elif self.args_only:
                try:
                    return json.loads(function_call["arguments"], strict=self.strict)
                except (json.JSONDecodeError, TypeError) as exc:
                    msg = f"Could not parse function call data: {exc}"
                    raise OutputParserException(msg) from exc
            else:
                try:
                    return {
                        **function_call,
                        "arguments": json.loads(
                            function_call["arguments"], strict=self.strict
                        ),
                    }
                except (json.JSONDecodeError, TypeError) as exc:
                    msg = f"Could not parse function call data: {exc}"
                    raise OutputParserException(msg) from exc
        except KeyError:
            return None

    # This method would be called by the default implementation of `parse_result`
    # but we're overriding that method so it's not needed.
    def parse(self, text: str) -> Any:
        """Parse the output of an LLM call to a JSON object.

View on GitHub (pinned to e32fa9a52e)

Solutions

  1. Increase max_tokens so the function call is not truncated
  2. Set strict=False on the parser to tolerate non-JSON-compliant strings (control characters, newlines)
  3. Catch OutputParserException and retry the call or repair the JSON (e.g. via a JSON-repair step) before parsing

Example fix

# before
parser = JsonOutputFunctionsParser(args_only=True, strict=True)

# after
parser = JsonOutputFunctionsParser(args_only=True, strict=False)  # tolerate newlines/control chars
Defensive patterns

Strategy: try-catch

Validate before calling

import json
args = result[0].message.additional_kwargs["function_call"]["arguments"]
try:
    json.loads(args)
except json.JSONDecodeError:
    ...  # repair or retry before invoking parser

Try / catch

from langchain_core.exceptions import OutputParserException
try:
    parsed = parser.parse_result(result)
except OutputParserException as e:
    # e.g. log raw arguments and retry with higher max_tokens
    logger.warning("function args invalid JSON: %s", e)

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of langchain-ai/langchain@e32fa9a52e (2026-08-14). Data as JSON: /api/errors/5a09390451c5bf16. Report an issue: GitHub.