Jump to content

Connect SuperML | Leeroopedia MCP: Equip your AI agents with best practices, code verification, and debugging knowledge. Powered by Leeroo — building Organizational Superintelligence. Contact us at founders@leeroo.com.

Implementation:Evidentlyai Evidently Legacy JSON Schema Match Feature

From Leeroopedia
Knowledge Sources
Domains ML Monitoring, Data Validation, JSON Schema Validation
Last Updated 2026-02-14 12:00 GMT

Overview

Provides a generated feature that validates whether JSON strings in a column conform to an expected schema, supporting both minimal and exact matching modes with optional type validation.

Description

The JSONSchemaMatch class extends GeneratedFeature to produce a categorical feature indicating whether JSON strings in a specified column match an expected schema. The class supports two matching modes:

  • Minimal match (default): Checks that all keys in the expected schema exist in the JSON object and are not None. Optionally validates that the values are of the expected types when validate_types is True.
  • Exact match: Requires the JSON object to have exactly the same set of keys as the expected schema (no extra, no missing keys), and also performs type validation.

The expected_schema parameter is a dictionary mapping key names to Python types (e.g., {"name": str, "age": int}). When exact_match is set to True, validate_types is automatically forced to True as well.

The feature column name follows the pattern {column_name}_json_schema_{exact|minimal}_match and the feature type is ColumnType.Categorical.

If the JSON string cannot be parsed (raises json.JSONDecodeError), the result for that row is False.

Usage

Use this feature to validate that structured JSON outputs from models or APIs conform to a required schema. This is particularly useful for monitoring LLM outputs that are expected to produce JSON with specific keys and value types, or for data quality checks on JSON-valued columns.

Code Reference

Source Location

Signature

class JSONSchemaMatch(GeneratedFeature):
    class Config:
        type_alias = "evidently:feature:JSONSchemaMatch"

    __feature_type__: ClassVar = ColumnType.Categorical
    column_name: str
    expected_schema: Dict[str, Type]
    validate_types: bool
    exact_match: bool

    def __init__(
        self,
        column_name: str,
        expected_schema: Dict[str, Type],
        validate_types: bool = False,
        exact_match: bool = False,
        display_name: Optional[str] = None,
    ): ...
    def generate_feature(self, data: pd.DataFrame, data_definition: DataDefinition) -> pd.DataFrame: ...
    def match_json_schema(self, json_text: str) -> bool: ...
    def _minimal_match(self, json_obj: Dict) -> bool: ...
    def _exact_match(self, json_obj: Dict) -> bool: ...
    def _as_column(self) -> ColumnName: ...

Import

from evidently.legacy.features.json_schema_match_feature import JSONSchemaMatch

I/O Contract

Inputs

Name Type Required Description
column_name str Yes Name of the column containing JSON strings to validate
expected_schema Dict[str, Type] Yes Dictionary mapping expected key names to their expected Python types
validate_types bool No Whether to validate value types against the schema (defaults to False; forced to True when exact_match is True)
exact_match bool No Whether to require exact key set matching (defaults to False)
display_name Optional[str] No Custom display name for the feature

Outputs

Name Type Description
return pd.DataFrame A single-column DataFrame with boolean values: True if the JSON matches the schema, False otherwise

Usage Examples

from evidently.legacy.features.json_schema_match_feature import JSONSchemaMatch

# Minimal match: check that required keys exist
schema_feature = JSONSchemaMatch(
    column_name="response",
    expected_schema={"name": str, "age": int, "email": str},
    validate_types=True
)

# Exact match: require exactly these keys with correct types
schema_feature_exact = JSONSchemaMatch(
    column_name="response",
    expected_schema={"name": str, "age": int},
    exact_match=True,
    display_name="Response Schema Validation"
)

Related Pages

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment