Home / File/ test_json_schema.py — langchain Source File

test_json_schema.py — langchain Source File

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

File python LangChainCore MessageInterface 2 imports 7 functions

Entity Profile

Dependency Diagram

graph LR
  54803af3_7979_cadf_df7b_bcd305ce919c["test_json_schema.py"]
  f69d6389_263d_68a4_7fbf_f14c0602a9ba["pytest"]
  54803af3_7979_cadf_df7b_bcd305ce919c --> f69d6389_263d_68a4_7fbf_f14c0602a9ba
  3ebdaf90_f47a_e0a0_d750_6bfde3220c5c["langchain_classic.evaluation.parsing.json_schema"]
  54803af3_7979_cadf_df7b_bcd305ce919c --> 3ebdaf90_f47a_e0a0_d750_6bfde3220c5c
  style 54803af3_7979_cadf_df7b_bcd305ce919c fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

import pytest

from langchain_classic.evaluation.parsing.json_schema import JsonSchemaEvaluator


@pytest.fixture
def json_schema_evaluator() -> JsonSchemaEvaluator:
    return JsonSchemaEvaluator()


@pytest.mark.requires("jsonschema")
def test_json_schema_evaluator_requires_input(
    json_schema_evaluator: JsonSchemaEvaluator,
) -> None:
    assert json_schema_evaluator.requires_input is False


@pytest.mark.requires("jsonschema")
def test_json_schema_evaluator_requires_reference(
    json_schema_evaluator: JsonSchemaEvaluator,
) -> None:
    assert json_schema_evaluator.requires_reference is True


@pytest.mark.requires("jsonschema")
def test_json_schema_evaluator_evaluation_name(
    json_schema_evaluator: JsonSchemaEvaluator,
) -> None:
    assert json_schema_evaluator.evaluation_name == "json_schema_validation"


@pytest.mark.requires("jsonschema")
def test_json_schema_evaluator_valid_prediction(
    json_schema_evaluator: JsonSchemaEvaluator,
) -> None:
    prediction = '{"name": "John", "age": 30}'
    reference = {
        "type": "object",
        "properties": {"name": {"type": "string"}, "age": {"type": "integer"}},
    }
    result = json_schema_evaluator._evaluate_strings(
        prediction=prediction,
        reference=reference,
    )
    assert result["score"] is True


@pytest.mark.requires("jsonschema")
def test_json_schema_evaluator_invalid_prediction(
    json_schema_evaluator: JsonSchemaEvaluator,
) -> None:
    prediction = '{"name": "John", "age": "30"}'  # age is a string instead of integer
    reference = {
        "type": "object",
        "properties": {"name": {"type": "string"}, "age": {"type": "integer"}},
    }
    result = json_schema_evaluator._evaluate_strings(
        prediction=prediction,
        reference=reference,
    )
    assert result["score"] is False
    assert "reasoning" in result


@pytest.mark.requires("jsonschema")
def test_json_schema_evaluator_missing_property(
    json_schema_evaluator: JsonSchemaEvaluator,
) -> None:
    prediction = '{"name": "John"}'  # age property is missing
    reference = {
        "type": "object",
        "properties": {"name": {"type": "string"}, "age": {"type": "integer"}},
        "required": ["name", "age"],
    }
    result = json_schema_evaluator._evaluate_strings(
        prediction=prediction,
        reference=reference,
    )
    assert result["score"] is False
    assert "reasoning" in result

Domain

Subdomains

Dependencies

  • langchain_classic.evaluation.parsing.json_schema
  • pytest

Frequently Asked Questions

What does test_json_schema.py do?
test_json_schema.py is a source file in the langchain codebase, written in python. It belongs to the LangChainCore domain, MessageInterface subdomain.
What functions are defined in test_json_schema.py?
test_json_schema.py defines 7 function(s): json_schema_evaluator, test_json_schema_evaluator_evaluation_name, test_json_schema_evaluator_invalid_prediction, test_json_schema_evaluator_missing_property, test_json_schema_evaluator_requires_input, test_json_schema_evaluator_requires_reference, test_json_schema_evaluator_valid_prediction.
What does test_json_schema.py depend on?
test_json_schema.py imports 2 module(s): langchain_classic.evaluation.parsing.json_schema, pytest.
Where is test_json_schema.py in the architecture?
test_json_schema.py is located at libs/langchain/tests/unit_tests/evaluation/parsing/test_json_schema.py (domain: LangChainCore, subdomain: MessageInterface, directory: libs/langchain/tests/unit_tests/evaluation/parsing).

Analyze Your Own Codebase

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

Try Supermodel Free