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 IsValidJSON Feature

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

Overview

Provides a generated feature that validates whether each value in a specified text column is valid JSON.

Description

The IsValidJSON class extends ApplyColumnGeneratedFeature to apply a per-row validation check that attempts to parse each cell value using Python's json.loads. If parsing succeeds, the feature returns True; if a ValueError is raised, it returns False. The feature type is ColumnType.Categorical since the output is a boolean classification.

The class uses a display_name_template class variable set to "JSON valid for {column_name}" which provides automatic display naming based on the target column. A custom display_name can also be provided at initialization.

Usage

Use this feature when monitoring or evaluating LLM outputs or other text data where valid JSON structure is expected. It is particularly useful in data quality checks for pipelines that produce or consume JSON payloads.

Code Reference

Source Location

Signature

class IsValidJSON(ApplyColumnGeneratedFeature):
    class Config:
        type_alias = "evidently:feature:IsValidJSON"

    __feature_type__: ClassVar = ColumnType.Categorical
    display_name_template: ClassVar = "JSON valid for {column_name}"

    def __init__(self, column_name: str, display_name: Optional[str] = None): ...
    def apply(self, value: Any): ...

Import

from evidently.legacy.features.is_valid_json_feature import IsValidJSON

I/O Contract

Inputs

Name Type Required Description
column_name str Yes Name of the text column in the DataFrame to validate as JSON
display_name Optional[str] No Custom display name for the feature (defaults to template-based name)

Outputs

Name Type Description
return bool (per row) True if the value is valid JSON, False otherwise

Usage Examples

from evidently.legacy.features.is_valid_json_feature import IsValidJSON

# Create the feature for a column named "response"
json_feature = IsValidJSON(column_name="response")

# With a custom display name
json_feature = IsValidJSON(column_name="api_output", display_name="API Output JSON Validity")

Related Pages

Page Connections

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