Home / Function/ test_parse() — langchain Function Reference

test_parse() — langchain Function Reference

Architecture documentation for the test_parse() function in test_structured_parser.py from the langchain codebase.

Entity Profile

Dependency Diagram

graph TD
  77258914_2653_ad53_f37f_5da21360a468["test_parse()"]
  5226734a_1415_1540_2bf2_1baef015b877["test_structured_parser.py"]
  77258914_2653_ad53_f37f_5da21360a468 -->|defined in| 5226734a_1415_1540_2bf2_1baef015b877
  style 77258914_2653_ad53_f37f_5da21360a468 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

libs/langchain/tests/unit_tests/output_parsers/test_structured_parser.py lines 8–30

def test_parse() -> None:
    """Test parsing structured output."""
    response_schemas = [
        ResponseSchema(name="name", description="desc"),
        ResponseSchema(name="age", description="desc"),
    ]
    parser = StructuredOutputParser.from_response_schemas(response_schemas)

    # Test valid JSON input
    text = '```json\n{"name": "John", "age": 30}\n```'
    expected_result = {"name": "John", "age": 30}
    result = parser.parse(text)
    assert result == expected_result, f"Expected {expected_result}, but got {result}"

    # Test invalid JSON input
    text = '```json\n{"name": "John"}\n```'
    try:
        parser.parse(text)
    except OutputParserException:
        pass  # Test passes if OutputParserException is raised
    else:
        msg = f"Expected OutputParserException, but got {parser.parse(text)}"
        raise AssertionError(msg)

Domain

Subdomains

Frequently Asked Questions

What does test_parse() do?
test_parse() is a function in the langchain codebase, defined in libs/langchain/tests/unit_tests/output_parsers/test_structured_parser.py.
Where is test_parse() defined?
test_parse() is defined in libs/langchain/tests/unit_tests/output_parsers/test_structured_parser.py at line 8.

Analyze Your Own Codebase

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

Try Supermodel Free