Home / Function/ test_parsed_strict() — langchain Function Reference

test_parsed_strict() — langchain Function Reference

Architecture documentation for the test_parsed_strict() function in test_responses_api.py from the langchain codebase.

Entity Profile

Dependency Diagram

graph TD
  59a98b00_1bcb_17f2_bccc_c8487861fc75["test_parsed_strict()"]
  992496d5_b7d4_139f_00cf_3e585d851f81["test_responses_api.py"]
  59a98b00_1bcb_17f2_bccc_c8487861fc75 -->|defined in| 992496d5_b7d4_139f_00cf_3e585d851f81
  style 59a98b00_1bcb_17f2_bccc_c8487861fc75 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

libs/partners/openai/tests/integration_tests/chat_models/test_responses_api.py lines 268–296

def test_parsed_strict() -> None:
    llm = ChatOpenAI(model=MODEL_NAME, use_responses_api=True)

    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=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=invalid_schema, strict=True
        )
    with pytest.raises(openai.BadRequestError):
        next(
            llm.stream(
                "Tell me a joke about cats.",
                response_format=invalid_schema,
                strict=True,
            )
        )

Domain

Subdomains

Frequently Asked Questions

What does test_parsed_strict() do?
test_parsed_strict() is a function in the langchain codebase, defined in libs/partners/openai/tests/integration_tests/chat_models/test_responses_api.py.
Where is test_parsed_strict() defined?
test_parsed_strict() is defined in libs/partners/openai/tests/integration_tests/chat_models/test_responses_api.py at line 268.

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free