Skip to content

fix(langchain,openai): only set strict=True on tools for OpenAI-compatible models in ProviderStrategy - #38370

Merged
Mason Daugherty (mdrxy) merged 4 commits into
masterfrom
cc/strict
Jun 22, 2026
Merged

fix(langchain,openai): only set strict=True on tools for OpenAI-compatible models in ProviderStrategy#38370
Mason Daugherty (mdrxy) merged 4 commits into
masterfrom
cc/strict

Conversation

@ccurme

Copy link
Copy Markdown
Collaborator

When using ProviderStrategy, create_agent unnecessarily sets strict=True on tools for all providers. This is only needed for OpenAI / chat completions. Here we unset strict. For OpenAI:

  1. We set it in BaseChatOpenAI.bind_tools (as a convenience to users calling model.bind_tools directly)
  2. We (redundantly) special-case OpenAI in the create_agent factory logic so that things will not break for users who upgrade langchain but not langchain-openai.

Note: payloads for OpenAI are tested here and appear unchanged: https://github.com/langchain-ai/langchain/blob/master/libs/langchain_v1/tests/unit_tests/agents/test_response_format_integration.py

Quick test:

from langchain.agents import create_agent
from langchain.agents.structured_output import ProviderStrategy
from pydantic import BaseModel

class Weather(BaseModel):
    temperature: float
    condition: str

def weather_tool(location: str) -> str:
    """Get the weather at a location."""
    return "Sunny and 75 degrees F."

for model in [
    "anthropic:claude-sonnet-4-6",
    "openai:gpt-5.4",
    "google_genai:gemini-3.5-flash",
]:

    agent = create_agent(
        model=model,
        tools=[weather_tool],
        response_format=ProviderStrategy(Weather),
    )
    
    result = agent.invoke({
        "messages": [{"role": "user", "content": "What's the weather in SF?"}]
    })
    
    print(result["structured_response"])

@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 internal langchain `langchain` package issues & PRs openai `langchain-openai` package issues & PRs size: S 50-199 LOC labels Jun 22, 2026
@mdrxy Mason Daugherty (mdrxy) changed the title fix(langchain,openai): only set strict=True on tools for OpenAI-compatible models in ProviderStrategy fix(langchain,openai): only set strict=True on tools for OpenAI-compatible models in ProviderStrategy Jun 22, 2026

@open-swe open-swe Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

✅ Open SWE Review: No issues found

Open SWE reviewed this PR and found no potential bugs to report.

Open in WebView Open SWE trace

@colifran Colin Francis (colifran) left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

LGTM!

@mdrxy
Mason Daugherty (mdrxy) merged commit 9ef324c into master Jun 22, 2026
94 of 95 checks passed
@mdrxy
Mason Daugherty (mdrxy) deleted the cc/strict branch June 22, 2026 22:11
@codspeed-hq

codspeed-hq Bot commented Jun 23, 2026

Copy link
Copy Markdown

Merging this PR will not alter performance

✅ 2 untouched benchmarks
⏩ 13 skipped benchmarks1


Comparing cc/strict (1115efc) with master (36be77b)2

Open in CodSpeed

Footnotes

  1. 13 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.

  2. No successful run was found on master (05b5af1) during the generation of this report, so 36be77b was used instead as the comparison base. There might be some changes unrelated to this pull request in this report.

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 internal langchain `langchain` package issues & PRs openai `langchain-openai` package issues & PRs size: S 50-199 LOC

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants