Home / File/ test_response_format_integration.py — langchain Source File

test_response_format_integration.py — langchain Source File

Architecture documentation for test_response_format_integration.py, a python file in the langchain codebase. 9 imports, 0 dependents.

File python LangChainCore Runnables 9 imports 6 functions 1 classes

Entity Profile

Dependency Diagram

graph LR
  52a46c82_b592_7c71_f552_b6b987060948["test_response_format_integration.py"]
  0029f612_c503_ebcf_a452_a0fae8c9f2c3["os"]
  52a46c82_b592_7c71_f552_b6b987060948 --> 0029f612_c503_ebcf_a452_a0fae8c9f2c3
  feec1ec4_6917_867b_d228_b134d0ff8099["typing"]
  52a46c82_b592_7c71_f552_b6b987060948 --> feec1ec4_6917_867b_d228_b134d0ff8099
  23cb242e_1754_041d_200a_553fcb8abe1b["unittest.mock"]
  52a46c82_b592_7c71_f552_b6b987060948 --> 23cb242e_1754_041d_200a_553fcb8abe1b
  f69d6389_263d_68a4_7fbf_f14c0602a9ba["pytest"]
  52a46c82_b592_7c71_f552_b6b987060948 --> f69d6389_263d_68a4_7fbf_f14c0602a9ba
  9444498b_8066_55c7_b3a2_1d90c4162a32["langchain_core.messages"]
  52a46c82_b592_7c71_f552_b6b987060948 --> 9444498b_8066_55c7_b3a2_1d90c4162a32
  dd5e7909_a646_84f1_497b_cae69735550e["pydantic"]
  52a46c82_b592_7c71_f552_b6b987060948 --> dd5e7909_a646_84f1_497b_cae69735550e
  d9a6942a_c37a_07f8_ed13_74d0fdc117be["langchain.agents"]
  52a46c82_b592_7c71_f552_b6b987060948 --> d9a6942a_c37a_07f8_ed13_74d0fdc117be
  6a1fbcf5_4f70_081d_b76c_92eaad743465["langchain.agents.structured_output"]
  52a46c82_b592_7c71_f552_b6b987060948 --> 6a1fbcf5_4f70_081d_b76c_92eaad743465
  2cad93e6_586a_5d28_a74d_4ec6fd4d2227["langchain_openai"]
  52a46c82_b592_7c71_f552_b6b987060948 --> 2cad93e6_586a_5d28_a74d_4ec6fd4d2227
  style 52a46c82_b592_7c71_f552_b6b987060948 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

r"""Test response_format for langchain-openai.

If tests fail, cassettes may need to be re-recorded.

To re-record cassettes:

1. Delete existing cassettes (`rm tests/cassettes/test_inference_to_*.yaml.gz`)
2. Re run the tests with a valid OPENAI_API_KEY in your environment:
```bash
OPENAI_API_KEY=... uv run python -m pytest tests/unit_tests/agents/test_response_format_integration.py
```

The cassettes are compressed. To read them:
```bash
gunzip -c "tests/cassettes/test_inference_to_native_output[True].yaml.gz" | \
    yq -o json . | \
    jq '.requests[].body |= (gsub("\n";"") | @base64d | fromjson) |
        .responses[].body.string |= (gsub("\n";"") | @base64d | fromjson)'
```

Or, in  Python:
```python
import json

from langchain_tests.conftest import CustomPersister, CustomSerializer

def bytes_encoder(obj):
    return obj.decode("utf-8", errors="replace")

path = "tests/cassettes/test_inference_to_native_output[True].yaml.gz"

requests, responses = CustomPersister().load_cassette(path, CustomSerializer())
assert len(requests) == len(responses)
for request, response in list(zip(requests, responses)):
    print("------ REQUEST ------")
    req = request._to_dict()
    req["body"] = json.loads(req["body"])
    print(json.dumps(req, indent=2, default=bytes_encoder))
    print("\n\n ------ RESPONSE ------")
    resp = response
    print(json.dumps(resp, indent=2, default=bytes_encoder))
print("\n\n")
```
"""  # noqa: E501

import os
from typing import TYPE_CHECKING, Any
from unittest.mock import patch

import pytest
from langchain_core.messages import HumanMessage
from pydantic import BaseModel, Field

from langchain.agents import create_agent
from langchain.agents.structured_output import ProviderStrategy, ToolStrategy

if TYPE_CHECKING:
    from langchain_openai import ChatOpenAI
else:
    ChatOpenAI = pytest.importorskip("langchain_openai").ChatOpenAI
// ... (130 more lines)

Domain

Subdomains

Dependencies

  • langchain.agents
  • langchain.agents.structured_output
  • langchain_core.messages
  • langchain_openai
  • os
  • pydantic
  • pytest
  • typing
  • unittest.mock

Frequently Asked Questions

What does test_response_format_integration.py do?
test_response_format_integration.py is a source file in the langchain codebase, written in python. It belongs to the LangChainCore domain, Runnables subdomain.
What functions are defined in test_response_format_integration.py?
test_response_format_integration.py defines 6 function(s): ChatOpenAI, get_weather, langchain_openai, test_inference_to_native_output, test_inference_to_tool_output, test_strict_mode.
What does test_response_format_integration.py depend on?
test_response_format_integration.py imports 9 module(s): langchain.agents, langchain.agents.structured_output, langchain_core.messages, langchain_openai, os, pydantic, pytest, typing, and 1 more.
Where is test_response_format_integration.py in the architecture?
test_response_format_integration.py is located at libs/langchain_v1/tests/unit_tests/agents/test_response_format_integration.py (domain: LangChainCore, subdomain: Runnables, directory: libs/langchain_v1/tests/unit_tests/agents).

Analyze Your Own Codebase

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

Try Supermodel Free