Skip to content

The agent engineering platform.

fix(openai): update test (#33659)

ccurme6ab0476676db
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 f3a70e936e..6ef779a295 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,
)
)