Skip to content

fix(openai): suppress Pydantic serializer warning on structured output parsed field#37727

Merged
ccurme (ccurme) merged 6 commits into
langchain-ai:masterfrom
Naominour:fix/openai-pydantic-parsed-warning
Jul 8, 2026
Merged

fix(openai): suppress Pydantic serializer warning on structured output parsed field#37727
ccurme (ccurme) merged 6 commits into
langchain-ai:masterfrom
Naominour:fix/openai-pydantic-parsed-warning

Conversation

@Naominour

@Naominour Naomi (Naominour) commented May 28, 2026

Copy link
Copy Markdown
Contributor

Closes #37723


The OpenAI SDK types the parsed field on ChatCompletionMessage restrictivel, when with_structured_output() populates it with an actual Pydantic model, model_dump() emits a PydanticSerializationUnexpectedValue warning even though the field is being excluded.

Adding warnings=False to the model_dump() call in _create_chat_result suppresses this. The field is already intentionally excluded and handled separately downstream, so no information is lost.

Also updates test_create_chat_result_avoids_parsed_model_dump_warning to use a mock type closer to the real SDK, ensuring the test actually catches this regression.

@github-actions github-actions Bot added fix For PRs that implement a fix integration PR made that is related to a provider partner package integration openai `langchain-openai` package issues & PRs size: XS < 50 LOC labels May 28, 2026
@github-actions

This comment has been minimized.

@github-actions github-actions Bot added size: S 50-199 LOC and removed size: XS < 50 LOC labels Jul 8, 2026
@github-actions github-actions Bot added size: M 200-499 LOC and removed size: S 50-199 LOC labels Jul 8, 2026
@ccurme ccurme (ccurme) merged commit fa01145 into langchain-ai:master Jul 8, 2026
85 checks passed
@ccurme

Copy link
Copy Markdown
Collaborator

Thanks for this! Released in langchain-openai 1.3.4.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

external fix For PRs that implement a fix integration PR made that is related to a provider partner package integration new-contributor openai `langchain-openai` package issues & PRs size: M 200-499 LOC

Projects

None yet

Development

Successfully merging this pull request may close these issues.

UserWarning: Pydantic serializer warnings:

2 participants