Skip to content

Conversation

mdrxy
Copy link
Collaborator

@mdrxy mdrxy commented Aug 14, 2025

Fixes #32492

@mdrxy mdrxy added the integration Related to a provider partner package integration label Aug 14, 2025
Copy link

vercel bot commented Aug 14, 2025

The latest updates on your projects. Learn more about Vercel for GitHub.

1 Skipped Deployment
Project Deployment Preview Comments Updated (UTC)
langchain Ignored Ignored Preview Sep 9, 2025 3:14pm

Copy link

codspeed-hq bot commented Aug 14, 2025

CodSpeed WallTime Performance Report

Merging #32551 will not alter performance

Comparing mdrxy/openai-fix-struc-out (2f8b9fa) with master (c124e67)

⚠️ Unknown Walltime execution environment detected

Using the Walltime instrument on standard Hosted Runners will lead to inconsistent data.

For the most accurate results, we recommend using CodSpeed Macro Runners: bare-metal machines fine-tuned for performance measurement consistency.

Summary

✅ 13 untouched benchmarks

Copy link

codspeed-hq bot commented Aug 14, 2025

CodSpeed Instrumentation Performance Report

Merging #32551 will not alter performance

Comparing mdrxy/openai-fix-struc-out (e7c7d2d) with master (c124e67)

Summary

✅ 14 untouched benchmarks

@mdrxy mdrxy requested a review from Copilot August 14, 2025 19:13
Copilot

This comment was marked as outdated.

mdrxy and others added 5 commits August 14, 2025 15:15
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@alexdlugo
Copy link

How do I request that this same fix get made to the js lib? Running into this issue currently

@mdrxy
Copy link
Collaborator Author

mdrxy commented Aug 18, 2025

@alexdlugo I've opened an issue on the js repo

@dsdsdsdsds-afk
Copy link

@mdrxy hi!
when this fix will be merged to main?

@dsdsdsdsds-afk
Copy link

@mdrxy hi! when this fix will be merged to main?

@ccurme hi! do you have any updates regarding this MR?

@mdrxy mdrxy requested a review from Copilot September 8, 2025 20:52
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR fixes a bug with structured output when using the OpenAI chat model with text parameters in model_kwargs. The fix ensures proper merging of text parameters when using structured output with the json_schema method.

  • Removes the previous error that prevented combining response_format and text parameters
  • Implements proper merging logic for text parameters with structured output format
  • Adds comprehensive test coverage for the fixed functionality

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
libs/partners/openai/langchain_openai/chat_models/base.py Fixed parameter merging logic in _construct_responses_api_payload to properly handle text parameters with structured output
libs/partners/openai/tests/unit_tests/chat_models/test_base.py Added test case to verify structured output works correctly with text parameters in model_kwargs

"format": {"type": "json_schema", **response_format["json_schema"]}
}
else:
structured_text = {}
Copy link
Preview

Copilot AI Sep 8, 2025

Choose a reason for hiding this comment

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

The else clause after line 3622 sets structured_text = {} but this empty dict serves no functional purpose since it's only used when there are existing text parameters or actual structured text content to merge. Consider removing this else clause and initializing structured_text = {} at the beginning of the responses.create path for clarity.

Copilot uses AI. Check for mistakes.

Comment on lines 2749 to 2750
# Type cast for mypy - structured_llm is a RunnableSequence with a
# RunnableBinding first element
Copy link
Preview

Copilot AI Sep 8, 2025

Choose a reason for hiding this comment

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

The comment mentions "Type cast for mypy" but the actual type casting occurs on lines 2751-2753. The comment should be moved closer to the actual casting operations or rewritten to better explain the structure being accessed.

Suggested change
# Type cast for mypy - structured_llm is a RunnableSequence with a
# RunnableBinding first element
# Type cast for mypy: structured_llm is a RunnableSequence,
# its first element is a RunnableBinding, and its bound is a ChatOpenAI.

Copilot uses AI. Check for mistakes.

@ccurme ccurme merged commit 4c6af2d into master Sep 9, 2025
72 checks passed
@ccurme ccurme deleted the mdrxy/openai-fix-struc-out branch September 9, 2025 15:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
integration Related to a provider partner package integration
Projects
None yet
Development

Successfully merging this pull request may close these issues.

ChatOpenAI: Cannot use GPT-5 verbosity parameter with structured output - ValueError on text/response_format conflict
4 participants