langchain-ai/langchain · error · ValueError

Input must be a valid OpenAI-format tool.

Error message

Input must be a valid OpenAI-format tool.

What it means

Error "Input must be a valid OpenAI-format tool." thrown in langchain-ai/langchain.

Source

Thrown at libs/core/langchain_core/utils/function_calling.py:606

        strict: If `True`, model output is guaranteed to exactly match the JSON Schema
            provided in the function definition.

            If `None`, `strict` argument will not be included in function definition.

    Raises:
        ValueError: If the input is not a valid OpenAI-format tool.

    Returns:
        A JSON schema representation of the input schema.
    """
    openai_tool = convert_to_openai_tool(schema, strict=strict)
    if (
        not isinstance(openai_tool, dict)
        or "function" not in openai_tool
        or "name" not in openai_tool["function"]
    ):
        error_message = "Input must be a valid OpenAI-format tool."
        raise ValueError(error_message)

    openai_function = openai_tool["function"]
    json_schema = {}
    json_schema["title"] = openai_function["name"]

    if "description" in openai_function:
        json_schema["description"] = openai_function["description"]

    if "parameters" in openai_function:
        parameters = openai_function["parameters"].copy()
        json_schema.update(parameters)

    return json_schema


@beta()
def tool_example_to_messages(
    input: str,

View on GitHub (pinned to e32fa9a52e)

Solutions

  1. Pass a dict in OpenAI tool format: {'type': 'function', 'function': {...}}.
  2. Convert other schema forms first with convert_to_openai_tool or convert_to_openai_function.

Example fix

tool = {'type': 'function', 'function': {'name': 'f', 'parameters': {...}}}

When it happens

Trigger: Raised when the input to a conversion expecting an OpenAI-format tool dict is missing required keys ('type': 'function' and a 'function' payload) or is of the wrong type.

Common situations: See trigger scenarios.


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