{"record":{"id":"599053c2b1becd36","repo":"langchain-ai/langchain","slug":"failed-to-generate-json-schema-for-model-name","errorCode":null,"errorMessage":"Failed to generate JSON schema for '{model_name}': {e}\n\nTool argument schemas must be JSON-serializable. If your schema includes custom Python classes, consider:\n  1. Converting them to Pydantic models with JSON-compatible fields\n  2. Using primitive types (str, int, float, bool, list, dict) instead\n  3. Passing the data as serialized JSON strings\n\n","messagePattern":"Failed to generate JSON schema for '(.+?)': (.+?)\n\nTool argument schemas must be JSON-serializable\\. If your schema includes custom Python classes, consider:\n  1\\. Converting them to Pydantic models with JSON-compatible fields\n  2\\. Using primitive types \\(str, int, float, bool, list, dict\\) instead\n  3\\. Passing the data as serialized JSON strings\n\n","errorType":"exception","errorClass":"PydanticInvalidForJsonSchema","httpStatus":null,"severity":"error","filePath":"libs/core/langchain_core/utils/function_calling.py","lineNumber":201,"sourceCode":"    try:\n        if hasattr(model, \"model_json_schema\"):\n            schema = model.model_json_schema()  # Pydantic 2\n        elif hasattr(model, \"schema\"):\n            schema = model.schema()  # Pydantic 1\n        else:\n            msg = \"Model must be a Pydantic model.\"\n            raise TypeError(msg)\n    except PydanticInvalidForJsonSchema as e:\n        model_name = getattr(model, \"__name__\", str(model))\n        msg = (\n            f\"Failed to generate JSON schema for '{model_name}': {e}\\n\\n\"\n            \"Tool argument schemas must be JSON-serializable. If your schema includes \"\n            \"custom Python classes, consider:\\n\"\n            \"  1. Converting them to Pydantic models with JSON-compatible fields\\n\"\n            \"  2. Using primitive types (str, int, float, bool, list, dict) instead\\n\"\n            \"  3. Passing the data as serialized JSON strings\\n\\n\"\n        )\n        raise PydanticInvalidForJsonSchema(msg) from e\n    return _convert_json_schema_to_openai_function(\n        schema, name=name, description=description, rm_titles=rm_titles\n    )\n\n\ndef _get_python_function_name(function: Callable[..., Any]) -> str:\n    \"\"\"Get the name of a Python function.\"\"\"\n    return function.__name__\n\n\ndef _convert_python_function_to_openai_function(\n    function: Callable[..., Any],\n) -> FunctionDescription:\n    \"\"\"Convert a Python function to an OpenAI function-calling API compatible dict.\n\n    Assumes the Python function has type hints and a docstring with a description. If\n    the docstring has Google Python style argument descriptions, these will be included\n    as well.","sourceCodeStart":183,"sourceCodeEnd":219,"githubUrl":"https://github.com/langchain-ai/langchain/blob/e32fa9a52eab3b61ad7a45399bfde59b3e580fc4/libs/core/langchain_core/utils/function_calling.py#L183-L219","documentation":"Error \"Failed to generate JSON schema for '{model_name}': {e}\n\nTool argument schemas must be JSON-serializable. If your schema includes custom Python classes, consider:\n  1. Converting them to Pydantic models with JSON-compatible fields\n  2. Using primitive types (str, int, float, bool, list, dict) instead\n  3. Passing the data as serialized JSON strings\n\n\" thrown in langchain-ai/langchain.","triggerScenarios":"Raised when model_json_schema()/schema() fails for a tool argument schema, typically because the Pydantic model contains custom Python types that are not JSON-serializable.","commonSituations":"See trigger scenarios.","solutions":["Convert custom Python classes in the schema to Pydantic models whose fields use JSON-compatible types.","Replace non-serializable types (e.g. datetime, Decimal, custom classes) with primitive types such as str, int, float, bool, list, or dict.","Pass complex data as serialized JSON strings instead of custom objects in the schema."],"exampleFix":"class Args(BaseModel):\n    created_at: str  # was datetime; serialize as ISO string instead","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"}