[GH-ISSUE #1420] Structured output - JSON schema error - (example in documentation does not work) #204

Open
opened 2026-02-17 17:19:23 -05:00 by yindo · 3 comments
Owner

Originally created by @davidsilva2841 on GitHub (Nov 12, 2025).
Original GitHub issue: https://github.com/langchain-ai/docs/issues/1420

Checked other resources

  • This is a bug, not a usage question.
  • I added a clear and descriptive title that summarizes this issue.
  • I used the GitHub search to find a similar question and didn't find it.
  • I am sure that this is a bug in LangChain rather than my code.
  • The bug is not resolved by updating to the latest stable version of LangChain (or the specific integration package).
  • This is not related to the langchain-community package.
  • I read what a minimal reproducible example is (https://stackoverflow.com/help/minimal-reproducible-example).
  • I posted a self-contained, minimal, reproducible example. A maintainer can copy it and run it AS IS.

Example Code

from langchain.agents import create_agent
from langchain_openai import AzureChatOpenAI

contact_info_schema = {
    "type": "object",
    "description": "Contact information for a person.",
    "properties": {
        "name": {"type": "string", "description": "The name of the person"},
        "email": {"type": "string", "description": "The email address of the person"},
        "phone": {"type": "string", "description": "The phone number of the person"},
    },
    "required": ["name", "email", "phone"],
}

agent = create_agent(
    model=AzureChatOpenAI(
        azure_deployment="gpt-5",
        api_version="2025-04-01-preview",
        azure_endpoint="SECRET", # ADD AUTH TO REPRODUCE
        model_version="gpt-5",
        api_key="SECRET", # ADD AUTH TO REPRODUCE
        temperature=0.0,
        frequency_penalty=0.0,
        presence_penalty=0.0,
        top_logprobs=1,
        seed=100,
        model_kwargs={
            "user": '{"appkey": "SECRET"}', # ADD AUTH TO REPRODUCE
        },
    ),
    response_format=contact_info_schema,  # Auto-selects ProviderStrategy
)

result = agent.invoke({
    "messages": [{"role": "user", "content": "Extract contact info from: John Doe, john@example.com, (555) 123-4567"}],
})

result["structured_response"]

Error Message and Stack Trace (if applicable)

Traceback (most recent call last):
  File "<input>", line 19, in <module>
  File "/Users/ds/co/rca-agent/server/.venv/lib/python3.13/site-packages/langgraph/pregel/main.py", line 3050, in invoke
    for chunk in self.stream(
                 ~~~~~~~~~~~^
        input,
        ^^^^^^
    ...<10 lines>...
        **kwargs,
        ^^^^^^^^^
    ):
    ^
  File "/Users/ds/co/rca-agent/server/.venv/lib/python3.13/site-packages/langgraph/pregel/main.py", line 2633, in stream
    for _ in runner.tick(
             ~~~~~~~~~~~^
        [t for t in loop.tasks.values() if not t.writes],
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    ...<2 lines>...
        schedule_task=loop.accept_push,
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    ):
    ^
  File "/Users/ds/co/rca-agent/server/.venv/lib/python3.13/site-packages/langgraph/pregel/_runner.py", line 167, in tick
    run_with_retry(
    ~~~~~~~~~~~~~~^
        t,
        ^^
    ...<10 lines>...
        },
        ^^
    )
    ^
  File "/Users/ds/co/rca-agent/server/.venv/lib/python3.13/site-packages/langgraph/pregel/_retry.py", line 42, in run_with_retry
    return task.proc.invoke(task.input, config)
           ~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^
  File "/Users/ds/co/rca-agent/server/.venv/lib/python3.13/site-packages/langgraph/_internal/_runnable.py", line 656, in invoke
    input = context.run(step.invoke, input, config, **kwargs)
  File "/Users/ds/co/rca-agent/server/.venv/lib/python3.13/site-packages/langgraph/_internal/_runnable.py", line 400, in invoke
    ret = self.func(*args, **kwargs)
  File "/Users/ds/co/rca-agent/server/.venv/lib/python3.13/site-packages/langchain/agents/factory.py", line 1073, in model_node
    response = _execute_model_sync(request)
  File "/Users/ds/co/rca-agent/server/.venv/lib/python3.13/site-packages/langchain/agents/factory.py", line 1041, in _execute_model_sync
    model_, effective_response_format = _get_bound_model(request)
                                        ~~~~~~~~~~~~~~~~^^^^^^^^^
  File "/Users/ds/co/rca-agent/server/.venv/lib/python3.13/site-packages/langchain/agents/factory.py", line 1013, in _get_bound_model
    raise ValueError(msg)
ValueError: ToolStrategy specifies tool 'response_format_e8e9' which wasn't declared in the original response format when creating the agent.
During task with name 'model' and id '(REMOVED FROM STACK TRACE)'

Description

The example from the documentation for JSON schema throws a ValueErrror.

The TypedDict example works for me, but the JSON schema example does not

System Info

System Information
------------------
> OS:  Darwin
> OS Version:  Darwin Kernel Version 24.6.0: Mon Aug 11 21:16:34 PDT 2025; root:xnu-11417.140.69.701.11~1/RELEASE_ARM64_T6020
> Python Version:  3.13.5 (main, Jun 11 2025, 15:36:57) [Clang 17.0.0 (clang-1700.0.13.3)]
Package Information
-------------------
> langchain_core: 1.0.4
> langchain: 1.0.5
> langsmith: 0.4.42
> langchain_aws: 1.0.0
> langchain_mcp_adapters: 0.1.12
> langchain_openai: 1.0.2
> langgraph_sdk: 0.2.9
> langgraph_supervisor: 0.0.30
Optional packages not installed
-------------------------------
> langserve
Other Dependencies
------------------
> beautifulsoup4: 4.14.2
> boto3: 1.40.71
> httpx: 0.28.1
> jsonpatch: 1.33
> langgraph: 1.0.3
> mcp: 1.21.0
> numpy: 2.3.4
> openai: 2.7.2
> opentelemetry-api: 1.38.0
> opentelemetry-exporter-otlp-proto-http: 1.38.0
> opentelemetry-sdk: 1.38.0
> orjson: 3.11.4
> packaging: 25.0
> pydantic: 2.12.4
> pyyaml: 6.0.3
> requests: 2.32.5
> requests-toolbelt: 1.0.0
> rich: 14.2.0
> tenacity: 9.1.2
> tiktoken: 0.12.0
> typing-extensions: 4.15.0
> zstandard: 0.25.0
Originally created by @davidsilva2841 on GitHub (Nov 12, 2025). Original GitHub issue: https://github.com/langchain-ai/docs/issues/1420 ### Checked other resources - [x] This is a bug, not a usage question. - [x] I added a clear and descriptive title that summarizes this issue. - [x] I used the GitHub search to find a similar question and didn't find it. - [x] I am sure that this is a bug in LangChain rather than my code. - [x] The bug is not resolved by updating to the latest stable version of LangChain (or the specific integration package). - [x] This is not related to the langchain-community package. - [x] I read what a minimal reproducible example is (https://stackoverflow.com/help/minimal-reproducible-example). - [x] I posted a self-contained, minimal, reproducible example. A maintainer can copy it and run it AS IS. ### Example Code ```python from langchain.agents import create_agent from langchain_openai import AzureChatOpenAI contact_info_schema = { "type": "object", "description": "Contact information for a person.", "properties": { "name": {"type": "string", "description": "The name of the person"}, "email": {"type": "string", "description": "The email address of the person"}, "phone": {"type": "string", "description": "The phone number of the person"}, }, "required": ["name", "email", "phone"], } agent = create_agent( model=AzureChatOpenAI( azure_deployment="gpt-5", api_version="2025-04-01-preview", azure_endpoint="SECRET", # ADD AUTH TO REPRODUCE model_version="gpt-5", api_key="SECRET", # ADD AUTH TO REPRODUCE temperature=0.0, frequency_penalty=0.0, presence_penalty=0.0, top_logprobs=1, seed=100, model_kwargs={ "user": '{"appkey": "SECRET"}', # ADD AUTH TO REPRODUCE }, ), response_format=contact_info_schema, # Auto-selects ProviderStrategy ) result = agent.invoke({ "messages": [{"role": "user", "content": "Extract contact info from: John Doe, john@example.com, (555) 123-4567"}], }) result["structured_response"] ``` ### Error Message and Stack Trace (if applicable) ``` Traceback (most recent call last): File "<input>", line 19, in <module> File "/Users/ds/co/rca-agent/server/.venv/lib/python3.13/site-packages/langgraph/pregel/main.py", line 3050, in invoke for chunk in self.stream( ~~~~~~~~~~~^ input, ^^^^^^ ...<10 lines>... **kwargs, ^^^^^^^^^ ): ^ File "/Users/ds/co/rca-agent/server/.venv/lib/python3.13/site-packages/langgraph/pregel/main.py", line 2633, in stream for _ in runner.tick( ~~~~~~~~~~~^ [t for t in loop.tasks.values() if not t.writes], ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ...<2 lines>... schedule_task=loop.accept_push, ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ): ^ File "/Users/ds/co/rca-agent/server/.venv/lib/python3.13/site-packages/langgraph/pregel/_runner.py", line 167, in tick run_with_retry( ~~~~~~~~~~~~~~^ t, ^^ ...<10 lines>... }, ^^ ) ^ File "/Users/ds/co/rca-agent/server/.venv/lib/python3.13/site-packages/langgraph/pregel/_retry.py", line 42, in run_with_retry return task.proc.invoke(task.input, config) ~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^ File "/Users/ds/co/rca-agent/server/.venv/lib/python3.13/site-packages/langgraph/_internal/_runnable.py", line 656, in invoke input = context.run(step.invoke, input, config, **kwargs) File "/Users/ds/co/rca-agent/server/.venv/lib/python3.13/site-packages/langgraph/_internal/_runnable.py", line 400, in invoke ret = self.func(*args, **kwargs) File "/Users/ds/co/rca-agent/server/.venv/lib/python3.13/site-packages/langchain/agents/factory.py", line 1073, in model_node response = _execute_model_sync(request) File "/Users/ds/co/rca-agent/server/.venv/lib/python3.13/site-packages/langchain/agents/factory.py", line 1041, in _execute_model_sync model_, effective_response_format = _get_bound_model(request) ~~~~~~~~~~~~~~~~^^^^^^^^^ File "/Users/ds/co/rca-agent/server/.venv/lib/python3.13/site-packages/langchain/agents/factory.py", line 1013, in _get_bound_model raise ValueError(msg) ValueError: ToolStrategy specifies tool 'response_format_e8e9' which wasn't declared in the original response format when creating the agent. During task with name 'model' and id '(REMOVED FROM STACK TRACE)' ``` ### Description The example from the [documentation](https://docs.langchain.com/oss/python/langchain/structured-output) for JSON schema throws a ValueErrror. The TypedDict example works for me, but the JSON schema example does not ### System Info ``` System Information ------------------ > OS: Darwin > OS Version: Darwin Kernel Version 24.6.0: Mon Aug 11 21:16:34 PDT 2025; root:xnu-11417.140.69.701.11~1/RELEASE_ARM64_T6020 > Python Version: 3.13.5 (main, Jun 11 2025, 15:36:57) [Clang 17.0.0 (clang-1700.0.13.3)] Package Information ------------------- > langchain_core: 1.0.4 > langchain: 1.0.5 > langsmith: 0.4.42 > langchain_aws: 1.0.0 > langchain_mcp_adapters: 0.1.12 > langchain_openai: 1.0.2 > langgraph_sdk: 0.2.9 > langgraph_supervisor: 0.0.30 Optional packages not installed ------------------------------- > langserve Other Dependencies ------------------ > beautifulsoup4: 4.14.2 > boto3: 1.40.71 > httpx: 0.28.1 > jsonpatch: 1.33 > langgraph: 1.0.3 > mcp: 1.21.0 > numpy: 2.3.4 > openai: 2.7.2 > opentelemetry-api: 1.38.0 > opentelemetry-exporter-otlp-proto-http: 1.38.0 > opentelemetry-sdk: 1.38.0 > orjson: 3.11.4 > packaging: 25.0 > pydantic: 2.12.4 > pyyaml: 6.0.3 > requests: 2.32.5 > requests-toolbelt: 1.0.0 > rich: 14.2.0 > tenacity: 9.1.2 > tiktoken: 0.12.0 > typing-extensions: 4.15.0 > zstandard: 0.25.0 ```
yindo added the bugexternal labels 2026-02-17 17:19:23 -05:00
Author
Owner

@parth-dobariya-hdrs commented on GitHub (Nov 13, 2025):

hi @davidsilva2841 , the issue is such that it is auto selecting ToolStrategy(internally) instead of ProviderStrategy
--gpt 5 supports structured output.

@parth-dobariya-hdrs commented on GitHub (Nov 13, 2025): hi @davidsilva2841 , the issue is such that it is auto selecting ToolStrategy(internally) instead of ProviderStrategy --gpt 5 supports structured output.
Author
Owner

@davidsilva2841 commented on GitHub (Nov 13, 2025):

Thanks @parth-dobariya-hdrs ! It looks like it can be fixed by wrapping contact_info_schema with ProviderStrategy

Fix

agent = create_agent(
    model=AzureChatOpenAI(
        azure_deployment="gpt-5",
        api_version="2025-04-01-preview",
        azure_endpoint="SECRET", # ADD AUTH TO REPRODUCE
        model_version="gpt-5",
        api_key="SECRET", # ADD AUTH TO REPRODUCE
        temperature=0.0,
        frequency_penalty=0.0,
        presence_penalty=0.0,
        top_logprobs=1,
        seed=100,
        model_kwargs={
            "user": '{"appkey": "SECRET"}', # ADD AUTH TO REPRODUCE
        },
    ),
    response_format=ProviderStrategy(contact_info_schema),  # <------ FIX
)
@davidsilva2841 commented on GitHub (Nov 13, 2025): Thanks @parth-dobariya-hdrs ! It looks like it can be fixed by wrapping `contact_info_schema` with `ProviderStrategy` # Fix ``` agent = create_agent( model=AzureChatOpenAI( azure_deployment="gpt-5", api_version="2025-04-01-preview", azure_endpoint="SECRET", # ADD AUTH TO REPRODUCE model_version="gpt-5", api_key="SECRET", # ADD AUTH TO REPRODUCE temperature=0.0, frequency_penalty=0.0, presence_penalty=0.0, top_logprobs=1, seed=100, model_kwargs={ "user": '{"appkey": "SECRET"}', # ADD AUTH TO REPRODUCE }, ), response_format=ProviderStrategy(contact_info_schema), # <------ FIX ) ```
Author
Owner

@hopegood commented on GitHub (Nov 13, 2025):

if using schema type,langchain automatically selects best strategy based on model capabilities

@hopegood commented on GitHub (Nov 13, 2025): if using schema type,langchain automatically selects best strategy based on model capabilities
yindo changed title from Structured output - JSON schema error - (example in documentation does not work) to [GH-ISSUE #1420] Structured output - JSON schema error - (example in documentation does not work) 2026-06-05 17:25:37 -04:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: langchain-ai/docs#204