[GH-ISSUE #479] gpt-5-nano ChatOpenAI.ainvoke() returns without errors but empty content #51

Closed
opened 2026-02-17 17:19:04 -05:00 by yindo · 8 comments
Owner

Originally created by @fantauzzi on GitHub (Aug 9, 2025).
Original GitHub issue: https://github.com/langchain-ai/docs/issues/479

Checked other resources

  • This is a bug, not a usage question. For questions, please use the LangChain Forum (https://forum.langchain.com/).
  • 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).
  • 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

import asyncio
from langchain_openai import ChatOpenAI
from langchain.schema import HumanMessage


async def main():
    prompt = ('Tell me a dad joke')

    llm = ChatOpenAI(model="gpt-5-nano", temperature=1, max_tokens=500)  # <== this gets an empty string in response.content
    # llm = ChatOpenAI(model="gpt-4.1-nano", temperature=1, max_tokens=500)  # <== This would work OK
    response = await llm.ainvoke([HumanMessage(content=prompt)])
    print(response.content)


asyncio.run(main())

Error Message and Stack Trace (if applicable)

No response

Description

I am using LangChain to send prompts to different LLM APIs with almost the same code. I call ainvoke() on instances of ChatOpenAI to send my prompts to different OpenAI models. WIth older models it works correctly, but when I send a prompt to gpt-5-nano the content attribute of ainvoke()'s return value is always an empty string.

Note that if I send the same prompt to gpt-5-nano via the command line, I get a meaningful response. E.g.

⮕ curl https://api.openai.com/v1/chat/completions \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer $OPENAI_API_KEY" \
  -d '{
    "model": "gpt-5-nano",
    "messages": [
      {"role": "user", "content": "Tell me a dad joke"}
    ]
  }' \
  | jq -r '.choices[0].message.content'
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100   978  100   866  100   112    211     27  0:00:04  0:00:04 --:--:--   238
Here's a dad joke for you: I'm reading a book on anti-gravity. It's impossible to put down.

System Info

System Information
------------------
> OS:  Linux
> OS Version:  langchain-ai/langchain#27~24.04.1-Ubuntu SMP PREEMPT_DYNAMIC Tue Jul 22 17:38:49 UTC 2
> Python Version:  3.13.5 (main, Jul 23 2025, 18:18:31) [GCC 13.3.0]

Package Information
-------------------
> langchain_core: 0.3.74
> langchain: 0.3.27
> langchain_community: 0.3.27
> langsmith: 0.4.13
> langchain_anthropic: 0.3.18
> langchain_huggingface: 0.3.1
> langchain_openai: 0.3.29
> langchain_text_splitters: 0.3.9

Optional packages not installed
-------------------------------
> langserve

Other Dependencies
------------------
> aiohttp<4.0.0,>=3.8.3: Installed. No version info available.
> anthropic<1,>=0.60.0: Installed. No version info available.
> async-timeout<5.0.0,>=4.0.0;: Installed. No version info available.
> dataclasses-json<0.7,>=0.5.7: Installed. No version info available.
> httpx-sse<1.0.0,>=0.4.0: Installed. No version info available.
> httpx<1,>=0.23.0: Installed. No version info available.
> huggingface-hub>=0.33.4: Installed. No version info available.
> jsonpatch<2.0,>=1.33: Installed. No version info available.
> langchain-anthropic;: Installed. No version info available.
> langchain-aws;: Installed. No version info available.
> langchain-azure-ai;: Installed. No version info available.
> langchain-cohere;: Installed. No version info available.
> langchain-community;: Installed. No version info available.
> langchain-core<1.0.0,>=0.3.66: Installed. No version info available.
> langchain-core<1.0.0,>=0.3.70: Installed. No version info available.
> langchain-core<1.0.0,>=0.3.72: Installed. No version info available.
> langchain-core<1.0.0,>=0.3.74: Installed. No version info available.
> langchain-deepseek;: Installed. No version info available.
> langchain-fireworks;: Installed. No version info available.
> langchain-google-genai;: Installed. No version info available.
> langchain-google-vertexai;: Installed. No version info available.
> langchain-groq;: Installed. No version info available.
> langchain-huggingface;: Installed. No version info available.
> langchain-mistralai;: Installed. No version info available.
> langchain-ollama;: Installed. No version info available.
> langchain-openai;: Installed. No version info available.
> langchain-perplexity;: Installed. No version info available.
> langchain-text-splitters<1.0.0,>=0.3.9: Installed. No version info available.
> langchain-together;: Installed. No version info available.
> langchain-xai;: Installed. No version info available.
> langchain<1.0.0,>=0.3.26: Installed. No version info available.
> langsmith-pyo3>=0.1.0rc2;: Installed. No version info available.
> langsmith>=0.1.125: Installed. No version info available.
> langsmith>=0.1.17: Installed. No version info available.
> langsmith>=0.3.45: Installed. No version info available.
> numpy>=1.26.2;: Installed. No version info available.
> numpy>=2.1.0;: Installed. No version info available.
> openai-agents>=0.0.3;: Installed. No version info available.
> openai<2.0.0,>=1.86.0: Installed. No version info available.
> opentelemetry-api>=1.30.0;: Installed. No version info available.
> opentelemetry-exporter-otlp-proto-http>=1.30.0;: Installed. No version info available.
> opentelemetry-sdk>=1.30.0;: Installed. No version info available.
> orjson>=3.9.14;: Installed. No version info available.
> packaging>=23.2: Installed. No version info available.
> pydantic-settings<3.0.0,>=2.4.0: Installed. No version info available.
> pydantic<3,>=1: Installed. No version info available.
> pydantic<3.0.0,>=2.7.4: Installed. No version info available.
> pydantic>=2.7.4: Installed. No version info available.
> pytest>=7.0.0;: Installed. No version info available.
> PyYAML>=5.3: Installed. No version info available.
> requests-toolbelt>=1.0.0: Installed. No version info available.
> requests<3,>=2: Installed. No version info available.
> requests>=2.0.0: Installed. No version info available.
> rich>=13.9.4;: Installed. No version info available.
> sentence-transformers>=2.6.0;: Installed. No version info available.
> SQLAlchemy<3,>=1.4: Installed. No version info available.
> tenacity!=8.4.0,<10,>=8.1.0: Installed. No version info available.
> tenacity!=8.4.0,<10.0.0,>=8.1.0: Installed. No version info available.
> tiktoken<1,>=0.7: Installed. No version info available.
> tokenizers>=0.19.1: Installed. No version info available.
> transformers>=4.39.0;: Installed. No version info available.
> typing-extensions>=4.7: Installed. No version info available.
> vcrpy>=7.0.0;: Installed. No version info available.
> zstandard>=0.23.0: Installed. No version info available.
Originally created by @fantauzzi on GitHub (Aug 9, 2025). Original GitHub issue: https://github.com/langchain-ai/docs/issues/479 ### Checked other resources - [x] This is a bug, not a usage question. For questions, please use the LangChain Forum (https://forum.langchain.com/). - [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] 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 import asyncio from langchain_openai import ChatOpenAI from langchain.schema import HumanMessage async def main(): prompt = ('Tell me a dad joke') llm = ChatOpenAI(model="gpt-5-nano", temperature=1, max_tokens=500) # <== this gets an empty string in response.content # llm = ChatOpenAI(model="gpt-4.1-nano", temperature=1, max_tokens=500) # <== This would work OK response = await llm.ainvoke([HumanMessage(content=prompt)]) print(response.content) asyncio.run(main()) ``` ### Error Message and Stack Trace (if applicable) _No response_ ### Description I am using LangChain to send prompts to different LLM APIs with almost the same code. I call `ainvoke()` on instances of `ChatOpenAI` to send my prompts to different OpenAI models. WIth older models it works correctly, but when I send a prompt to `gpt-5-nano` the `content` attribute of `ainvoke()`'s return value is always an empty string. Note that if I send the same prompt to `gpt-5-nano` via the command line, I get a meaningful response. E.g. ```bash ⮕ curl https://api.openai.com/v1/chat/completions \ -H "Content-Type: application/json" \ -H "Authorization: Bearer $OPENAI_API_KEY" \ -d '{ "model": "gpt-5-nano", "messages": [ {"role": "user", "content": "Tell me a dad joke"} ] }' \ | jq -r '.choices[0].message.content' % Total % Received % Xferd Average Speed Time Time Time Current Dload Upload Total Spent Left Speed 100 978 100 866 100 112 211 27 0:00:04 0:00:04 --:--:-- 238 Here's a dad joke for you: I'm reading a book on anti-gravity. It's impossible to put down. ``` ### System Info ```bash System Information ------------------ > OS: Linux > OS Version: langchain-ai/langchain#27~24.04.1-Ubuntu SMP PREEMPT_DYNAMIC Tue Jul 22 17:38:49 UTC 2 > Python Version: 3.13.5 (main, Jul 23 2025, 18:18:31) [GCC 13.3.0] Package Information ------------------- > langchain_core: 0.3.74 > langchain: 0.3.27 > langchain_community: 0.3.27 > langsmith: 0.4.13 > langchain_anthropic: 0.3.18 > langchain_huggingface: 0.3.1 > langchain_openai: 0.3.29 > langchain_text_splitters: 0.3.9 Optional packages not installed ------------------------------- > langserve Other Dependencies ------------------ > aiohttp<4.0.0,>=3.8.3: Installed. No version info available. > anthropic<1,>=0.60.0: Installed. No version info available. > async-timeout<5.0.0,>=4.0.0;: Installed. No version info available. > dataclasses-json<0.7,>=0.5.7: Installed. No version info available. > httpx-sse<1.0.0,>=0.4.0: Installed. No version info available. > httpx<1,>=0.23.0: Installed. No version info available. > huggingface-hub>=0.33.4: Installed. No version info available. > jsonpatch<2.0,>=1.33: Installed. No version info available. > langchain-anthropic;: Installed. No version info available. > langchain-aws;: Installed. No version info available. > langchain-azure-ai;: Installed. No version info available. > langchain-cohere;: Installed. No version info available. > langchain-community;: Installed. No version info available. > langchain-core<1.0.0,>=0.3.66: Installed. No version info available. > langchain-core<1.0.0,>=0.3.70: Installed. No version info available. > langchain-core<1.0.0,>=0.3.72: Installed. No version info available. > langchain-core<1.0.0,>=0.3.74: Installed. No version info available. > langchain-deepseek;: Installed. No version info available. > langchain-fireworks;: Installed. No version info available. > langchain-google-genai;: Installed. No version info available. > langchain-google-vertexai;: Installed. No version info available. > langchain-groq;: Installed. No version info available. > langchain-huggingface;: Installed. No version info available. > langchain-mistralai;: Installed. No version info available. > langchain-ollama;: Installed. No version info available. > langchain-openai;: Installed. No version info available. > langchain-perplexity;: Installed. No version info available. > langchain-text-splitters<1.0.0,>=0.3.9: Installed. No version info available. > langchain-together;: Installed. No version info available. > langchain-xai;: Installed. No version info available. > langchain<1.0.0,>=0.3.26: Installed. No version info available. > langsmith-pyo3>=0.1.0rc2;: Installed. No version info available. > langsmith>=0.1.125: Installed. No version info available. > langsmith>=0.1.17: Installed. No version info available. > langsmith>=0.3.45: Installed. No version info available. > numpy>=1.26.2;: Installed. No version info available. > numpy>=2.1.0;: Installed. No version info available. > openai-agents>=0.0.3;: Installed. No version info available. > openai<2.0.0,>=1.86.0: Installed. No version info available. > opentelemetry-api>=1.30.0;: Installed. No version info available. > opentelemetry-exporter-otlp-proto-http>=1.30.0;: Installed. No version info available. > opentelemetry-sdk>=1.30.0;: Installed. No version info available. > orjson>=3.9.14;: Installed. No version info available. > packaging>=23.2: Installed. No version info available. > pydantic-settings<3.0.0,>=2.4.0: Installed. No version info available. > pydantic<3,>=1: Installed. No version info available. > pydantic<3.0.0,>=2.7.4: Installed. No version info available. > pydantic>=2.7.4: Installed. No version info available. > pytest>=7.0.0;: Installed. No version info available. > PyYAML>=5.3: Installed. No version info available. > requests-toolbelt>=1.0.0: Installed. No version info available. > requests<3,>=2: Installed. No version info available. > requests>=2.0.0: Installed. No version info available. > rich>=13.9.4;: Installed. No version info available. > sentence-transformers>=2.6.0;: Installed. No version info available. > SQLAlchemy<3,>=1.4: Installed. No version info available. > tenacity!=8.4.0,<10,>=8.1.0: Installed. No version info available. > tenacity!=8.4.0,<10.0.0,>=8.1.0: Installed. No version info available. > tiktoken<1,>=0.7: Installed. No version info available. > tokenizers>=0.19.1: Installed. No version info available. > transformers>=4.39.0;: Installed. No version info available. > typing-extensions>=4.7: Installed. No version info available. > vcrpy>=7.0.0;: Installed. No version info available. > zstandard>=0.23.0: Installed. No version info available. ```
yindo added the langchain label 2026-02-17 17:19:04 -05:00
yindo closed this issue 2026-02-17 17:19:04 -05:00
Author
Owner

@onestardao commented on GitHub (Aug 9, 2025):

this behavior matches No.6 – Logic Collapse & Recovery from my failure map.
the call path is valid, but the reasoning chain hits a dead-end and returns an empty payload without triggering an explicit error.
i have a MIT-licensed patch for this failure mode (already field-tested, with a star from the tesseract.js author).
if you’re curious, i can share the doc that explains how to fix it step-by-step.

@onestardao commented on GitHub (Aug 9, 2025): this behavior matches No.6 – Logic Collapse & Recovery from my failure map. the call path is valid, but the reasoning chain hits a dead-end and returns an empty payload without triggering an explicit error. i have a MIT-licensed patch for this failure mode (already field-tested, with a star from the tesseract.js author). if you’re curious, i can share the doc that explains how to fix it step-by-step.
Author
Owner

@alexferrari88 commented on GitHub (Aug 10, 2025):

I can confirm the bug as I am experiencing it as well

@alexferrari88 commented on GitHub (Aug 10, 2025): I can confirm the bug as I am experiencing it as well
Author
Owner

@siddarthreddygsr commented on GitHub (Aug 10, 2025):

I am facing this issue only in ainvoke

@siddarthreddygsr commented on GitHub (Aug 10, 2025): I am facing this issue only in ainvoke
Author
Owner

@developermarshak commented on GitHub (Aug 16, 2025):

@fantauzzi

It’s not a LangChain bug. The point is that the entire GPT-5 family are reasoning models. The token limit applies not only to the model’s final output but also to its internal reasoning.

In your case, all the tokens are being consumed by reasoning, which is why you’re not getting any output.

GPT-4.1 is not a reasoning model, so you don’t encounter this issue there.

When you make the request with curl, you don’t pass a token limit, so the problem doesn’t reproduce.

@developermarshak commented on GitHub (Aug 16, 2025): @fantauzzi It’s not a LangChain bug. The point is that the entire GPT-5 family are reasoning models. The token limit applies not only to the model’s final output but also to its internal reasoning. In your case, all the tokens are being consumed by reasoning, which is why you’re not getting any output. GPT-4.1 is not a reasoning model, so you don’t encounter this issue there. When you make the request with curl, you don’t pass a token limit, so the problem doesn’t reproduce.
Author
Owner

@APC-NOOKUBO commented on GitHub (Aug 21, 2025):

I'm facing the same issue on Azure OpenAI. Here are my package versions

    "langchain-core==0.3.74",
    "langchain-community==0.3.27",
    "langchain-openai==0.3.30",

I've observed that tokens are generated when using a tool call, but not when using ainvoke.

@APC-NOOKUBO commented on GitHub (Aug 21, 2025): I'm facing the same issue on Azure OpenAI. Here are my package versions ``` "langchain-core==0.3.74", "langchain-community==0.3.27", "langchain-openai==0.3.30", ``` I've observed that tokens are generated when using a tool call, but not when using ainvoke.
Author
Owner

@PrynAI commented on GitHub (Aug 29, 2025):

@fantauzzi

It’s not a LangChain bug. The point is that the entire GPT-5 family are reasoning models. The token limit applies not only to the model’s final output but also to its internal reasoning.

In your case, all the tokens are being consumed by reasoning, which is why you’re not getting any output.

GPT-4.1 is not a reasoning model, so you don’t encounter this issue there.

When you make the request with curl, you don’t pass a token limit, so the problem doesn’t reproduce.

Thank you. Reasoning tokens are higher than what i have set. so, either i must increase token limit to a max, so that never reasoning tokens should max out or I must remove token limit. Finally, i have removed token limit to work all the time

@PrynAI commented on GitHub (Aug 29, 2025): > [@fantauzzi](https://github.com/fantauzzi) > > It’s not a LangChain bug. The point is that the entire GPT-5 family are reasoning models. The token limit applies not only to the model’s final output but also to its internal reasoning. > > In your case, all the tokens are being consumed by reasoning, which is why you’re not getting any output. > > GPT-4.1 is not a reasoning model, so you don’t encounter this issue there. > > When you make the request with curl, you don’t pass a token limit, so the problem doesn’t reproduce. Thank you. Reasoning tokens are higher than what i have set. so, either i must increase token limit to a max, so that never reasoning tokens should max out or I must remove token limit. Finally, i have removed token limit to work all the time
Author
Owner

@siddarthreddygsr commented on GitHub (Aug 29, 2025):

But isnt it overthinking if it using more than 500 tokens just for reasoning on whats a good dad joke

@siddarthreddygsr commented on GitHub (Aug 29, 2025): But isnt it overthinking if it using more than 500 tokens just for reasoning on whats a good dad joke
Author
Owner

@mdrxy commented on GitHub (Sep 10, 2025):

@siddarthreddygsr depends on how good the joke is

We should probably update the docs to warn about this @lnhsingh

@mdrxy commented on GitHub (Sep 10, 2025): @siddarthreddygsr depends on how good the joke is We should probably update the docs to warn about this @lnhsingh
yindo changed title from gpt-5-nano `ChatOpenAI.ainvoke()` returns without errors but empty content to [GH-ISSUE #479] gpt-5-nano `ChatOpenAI.ainvoke()` returns without errors but empty content 2026-06-05 17:24:46 -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#51