Skip to content

fix(openai): accept valid responses that are falsy at runtime - #35307

Merged
ccurme (ccurme) merged 2 commits into
langchain-ai:masterfrom
akaIDIOT:akaidiot/accept-falsy-structured-result
Feb 19, 2026
Merged

fix(openai): accept valid responses that are falsy at runtime#35307
ccurme (ccurme) merged 2 commits into
langchain-ai:masterfrom
akaIDIOT:akaidiot/accept-falsy-structured-result

Conversation

@akaIDIOT

Copy link
Copy Markdown
Contributor

When using structured output through model.with_structured_output(MyModel) using a MyModel class definition that happens to implement magic methods that influence the truthiness of an instance, a valid response that evaluates to False causes _oai_structured_outputs_parser to fall through all of the options reading the response, concluding that the response must be faulty. Moving from a truthiness check to a presence check (is not None) fixes this; valid responses of my model class that happen to have length 0 are now returned as expected.

See the added test for a minimal example of this behaviour (the test fails without the single line change in langchain_openai/chat_models/base.py).

@github-actions github-actions Bot added external integration PR made that is related to a provider partner package integration openai `langchain-openai` package issues & PRs fix For PRs that implement a fix and removed external labels Feb 18, 2026
@codspeed-hq

codspeed-hq Bot commented Feb 18, 2026

Copy link
Copy Markdown

Merging this PR will not alter performance

✅ 6 untouched benchmarks
⏩ 29 skipped benchmarks1


Comparing akaIDIOT:akaidiot/accept-falsy-structured-result (93ee302) with master (b004103)

Open in CodSpeed

Footnotes

  1. 29 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports.

@ccurme ccurme (ccurme) left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you!

@ccurme
ccurme (ccurme) merged commit 5c6f8fe into langchain-ai:master Feb 19, 2026
81 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants