langchain - ✅(Solved) Fix PydanticSerializationUnexpectedValue warning when using structured output for AzureChatOpenAI [1 pull requests, 1 comments, 2 participants]

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…
GitHub stats
langchain-ai/langchain#36606Fetched 2026-04-09 07:51:00
View on GitHub
Comments
1
Participants
2
Timeline
7
Reactions
0
Timeline (top)
labeled ×3commented ×1issue_type_added ×1referenced ×1

Using structured output for AzureChatOpenAI produces a serializer warning.

Error Message

Error Message and Stack Trace (if applicable)

Root Cause

Using structured output for AzureChatOpenAI produces a serializer warning.

Fix Action

Fix / Workaround

  • 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 posted a self-contained, minimal, reproducible example. A maintainer can copy it and run it AS IS.

Other Dependencies

httpx: 0.28.1 jsonpatch: 1.33 openai: 2.30.0 orjson: 3.11.8 packaging: 26.0 pydantic: 2.12.5 pyyaml: 6.0.3 requests: 2.33.1 requests-toolbelt: 1.0.0 tenacity: 9.1.4 tiktoken: 0.12.0 typing-extensions: 4.15.0 uuid-utils: 0.14.1 xxhash: 3.6.0 zstandard: 0.25.0

PR fix notes

PR #36632: fix(partners): structured output for AzureChatOpenAI

Description (problem / solution / changelog)

Fixes #36606

Updated the conditions for enabling stream_usage in order to fix PydanticSerializationUnexpectedValue warning when using structured output for AzureChatOpenAI.

Changed files

  • libs/partners/openai/langchain_openai/chat_models/base.py (modified, +0/-1)

Code Example

from langchain_openai import AzureChatOpenAI
from pydantic.main import BaseModel

gpt4_model = AzureChatOpenAI(...)

class ModelOutput(BaseModel):
    output: str

gpt4_model.with_structured_output(ModelOutput).invoke("What is the capital of France?")

---

PydanticSerializationUnexpectedValue(Expected `none` - serialized value may not be as expected [field_name='parsed', input_value=ModelOutput(output='The c...al of France is Paris.'), input_type=ModelOutput])
  return self.__pydantic_serializer__.to_python(
RAW_BUFFERClick to expand / collapse

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 posted a self-contained, minimal, reproducible example. A maintainer can copy it and run it AS IS.

Package (Required)

  • langchain
  • langchain-openai
  • langchain-anthropic
  • langchain-classic
  • langchain-core
  • langchain-model-profiles
  • langchain-tests
  • langchain-text-splitters
  • langchain-chroma
  • langchain-deepseek
  • langchain-exa
  • langchain-fireworks
  • langchain-groq
  • langchain-huggingface
  • langchain-mistralai
  • langchain-nomic
  • langchain-ollama
  • langchain-openrouter
  • langchain-perplexity
  • langchain-qdrant
  • langchain-xai
  • Other / not sure / general

Related Issues / PRs

PydanticSerializationUnexpectedValue warning when using structured output #35538

Reproduction Steps / Example Code (Python)

from langchain_openai import AzureChatOpenAI
from pydantic.main import BaseModel

gpt4_model = AzureChatOpenAI(...)

class ModelOutput(BaseModel):
    output: str

gpt4_model.with_structured_output(ModelOutput).invoke("What is the capital of France?")

Error Message and Stack Trace (if applicable)

PydanticSerializationUnexpectedValue(Expected `none` - serialized value may not be as expected [field_name='parsed', input_value=ModelOutput(output='The c...al of France is Paris.'), input_type=ModelOutput])
  return self.__pydantic_serializer__.to_python(

Description

Using structured output for AzureChatOpenAI produces a serializer warning.

System Info

System Information

OS: Linux OS Version: #1 SMP PREEMPT_DYNAMIC Thu Jun 5 18:30:46 UTC 2025 Python Version: 3.12.3 (main, Mar 3 2026, 12:15:18) [GCC 13.3.0]

Package Information

langchain_core: 1.2.27 langsmith: 0.7.26 langchain_openai: 1.1.12

Optional packages not installed

deepagents deepagents-cli

Other Dependencies

httpx: 0.28.1 jsonpatch: 1.33 openai: 2.30.0 orjson: 3.11.8 packaging: 26.0 pydantic: 2.12.5 pyyaml: 6.0.3 requests: 2.33.1 requests-toolbelt: 1.0.0 tenacity: 9.1.4 tiktoken: 0.12.0 typing-extensions: 4.15.0 uuid-utils: 0.14.1 xxhash: 3.6.0 zstandard: 0.25.0

extent analysis

TL;DR

The issue can be resolved by adjusting the Pydantic model to correctly handle the serialized output from AzureChatOpenAI.

Guidance

  • Review the ModelOutput class to ensure it accurately represents the expected output structure from AzureChatOpenAI, considering the parsed field mentioned in the error message.
  • Verify that the output field in ModelOutput is correctly defined to handle the specific format of the response from the model, potentially requiring adjustments to the Pydantic model's configuration or the use of a different data type.
  • Check if updating Pydantic to the latest version could resolve the PydanticSerializationUnexpectedValue warning, as the issue might be related to a version-specific bug.
  • Consider adding custom serialization logic to handle the specific output format of AzureChatOpenAI if the standard Pydantic serialization does not work as expected.

Example

from langchain_openai import AzureChatOpenAI
from pydantic.main import BaseModel

class ModelOutput(BaseModel):
    output: str
    parsed: dict = None  # Example adjustment to handle 'parsed' field

gpt4_model = AzureChatOpenAI(...)
gpt4_model.with_structured_output(ModelOutput).invoke("What is the capital of France?")

Notes

The provided example code snippet is a minimal illustration and might require further adjustments based on the actual output structure of AzureChatOpenAI. Ensure that any changes to the Pydantic model align with the expected output format to avoid serialization errors.

Recommendation

Apply a workaround by adjusting the Pydantic model to correctly handle the output from AzureChatOpenAI, as the issue seems related to serialization and not a direct bug in LangChain or its integrations.

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING