From 6ab0476676db867f69223494b4020730e5c67dcf Mon Sep 17 00:00:00 2001 From: ccurme Date: Fri, 24 Oct 2025 11:04:33 -0400 Subject: [PATCH] fix(openai): update test (#33659) --- .../chat_models/test_responses_api.py | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/libs/partners/openai/tests/integration_tests/chat_models/test_responses_api.py b/libs/partners/openai/tests/integration_tests/chat_models/test_responses_api.py index f3a70e936e5..6ef779a2953 100644 --- a/libs/partners/openai/tests/integration_tests/chat_models/test_responses_api.py +++ b/libs/partners/openai/tests/integration_tests/chat_models/test_responses_api.py @@ -18,6 +18,7 @@ from pydantic import BaseModel from typing_extensions import TypedDict from langchain_openai import ChatOpenAI, custom_tool +from langchain_openai.chat_models.base import _convert_to_openai_response_format MODEL_NAME = "gpt-4o-mini" @@ -247,24 +248,30 @@ def test_parsed_dict_schema(schema: Any) -> None: def test_parsed_strict() -> None: llm = ChatOpenAI(model=MODEL_NAME, use_responses_api=True) - class InvalidJoke(TypedDict): + class Joke(TypedDict): setup: Annotated[str, ..., "The setup of the joke"] punchline: Annotated[str, None, "The punchline of the joke"] + schema = _convert_to_openai_response_format(Joke) + invalid_schema = cast(dict, _convert_to_openai_response_format(Joke, strict=True)) + invalid_schema["json_schema"]["schema"]["required"] = ["setup"] # make invalid + # Test not strict - response = llm.invoke("Tell me a joke", response_format=InvalidJoke) + response = llm.invoke("Tell me a joke", response_format=schema) parsed = json.loads(response.text) assert parsed == response.additional_kwargs["parsed"] # Test strict with pytest.raises(openai.BadRequestError): llm.invoke( - "Tell me a joke about cats.", response_format=InvalidJoke, strict=True + "Tell me a joke about cats.", response_format=invalid_schema, strict=True ) with pytest.raises(openai.BadRequestError): next( llm.stream( - "Tell me a joke about cats.", response_format=InvalidJoke, strict=True + "Tell me a joke about cats.", + response_format=invalid_schema, + strict=True, ) )