Jump to content

Connect Leeroopedia MCP: Equip your AI agents to search best practices, build plans, verify code, diagnose failures, and look up hyperparameter defaults.

Implementation:Evidentlyai Evidently Legacy Text Contains Feature

From Leeroopedia
Knowledge Sources
Domains NLP, Feature Engineering, Text Analysis
Last Updated 2026-02-14 12:00 GMT

Overview

This module provides four generated feature classes -- Contains, DoesNotContain, ItemMatch, and ItemNoMatch -- for checking whether text columns contain or do not contain specified substrings or items, with configurable matching modes and case sensitivity.

Description

All four classes extend GeneratedFeature and produce ColumnType.Categorical outputs (boolean-like). They support two matching modes:

  • "any" -- returns True if any of the specified items is found (or not found, for negation variants).
  • "all" -- returns True only if all specified items are found (or not found, for negation variants).

Contains and DoesNotContain operate on a single text column against a static list of items. Contains checks if specified substrings appear in the text; DoesNotContain returns the logical negation. Both support case_sensitive toggling.

ItemMatch and ItemNoMatch operate across two columns: they check whether words from a second column appear (or do not appear) in the text of the first column. These require exactly two column names to be provided.

Each class generates a unique feature column name based on the column name(s), item list, case sensitivity, and mode.

Usage

Use these features when you need to derive boolean flags indicating substring presence or absence in text data. Typical use cases include checking whether model outputs contain required keywords, verifying that responses exclude forbidden terms, or comparing text across two columns for item-level matching.

Code Reference

Source Location

Signature

class Contains(GeneratedFeature):
    class Config:
        type_alias = "evidently:feature:Contains"
    __feature_type__: ClassVar = ColumnType.Categorical
    column_name: str
    items: List[str]
    case_sensitive: bool
    mode: str
    def __init__(self, column_name: str, items: List[str], case_sensitive: bool = True,
                 mode: str = "any", display_name: Optional[str] = None): ...
    def generate_feature(self, data: pd.DataFrame, data_definition: DataDefinition) -> pd.DataFrame: ...

class DoesNotContain(GeneratedFeature):
    class Config:
        type_alias = "evidently:feature:DoesNotContain"
    __feature_type__: ClassVar = ColumnType.Categorical
    column_name: str
    items: List[str]
    case_sensitive: bool
    mode: str
    def __init__(self, column_name: str, items: List[str], case_sensitive: bool = True,
                 mode: str = "any", display_name: Optional[str] = None): ...
    def generate_feature(self, data: pd.DataFrame, data_definition: DataDefinition) -> pd.DataFrame: ...

class ItemMatch(GeneratedFeature):
    class Config:
        type_alias = "evidently:feature:ItemMatch"
    __feature_type__: ClassVar = ColumnType.Categorical
    columns: List[str]
    case_sensitive: bool
    mode: str
    def __init__(self, columns: List[str], case_sensitive: bool = True,
                 mode: str = "any", display_name: Optional[str] = None): ...
    def generate_feature(self, data: pd.DataFrame, data_definition: DataDefinition) -> pd.DataFrame: ...

class ItemNoMatch(GeneratedFeature):
    class Config:
        type_alias = "evidently:feature:ItemNoMatch"
    __feature_type__: ClassVar = ColumnType.Categorical
    columns: List[str]
    case_sensitive: bool
    mode: str
    def __init__(self, columns: List[str], case_sensitive: bool = True,
                 mode: str = "any", display_name: Optional[str] = None): ...
    def generate_feature(self, data: pd.DataFrame, data_definition: DataDefinition) -> pd.DataFrame: ...

Import

from evidently.legacy.features.text_contains_feature import Contains
from evidently.legacy.features.text_contains_feature import DoesNotContain
from evidently.legacy.features.text_contains_feature import ItemMatch
from evidently.legacy.features.text_contains_feature import ItemNoMatch

I/O Contract

Inputs (Contains / DoesNotContain)

Name Type Required Description
column_name str Yes Name of the text column to search
items List[str] Yes List of substrings to search for
case_sensitive bool No Whether matching is case-sensitive (default: True)
mode str No Matching mode: "any" or "all" (default: "any")
display_name Optional[str] No Custom display name for the feature column

Inputs (ItemMatch / ItemNoMatch)

Name Type Required Description
columns List[str] Yes Exactly two column names: [text_column, items_column]
case_sensitive bool No Whether matching is case-sensitive (default: True)
mode str No Matching mode: "any" or "all" (default: "any")
display_name Optional[str] No Custom display name for the feature column

Outputs

Name Type Description
generated feature column bool True/False indicating whether the text contains (or does not contain) the specified items according to the chosen mode

Usage Examples

from evidently.legacy.features.text_contains_feature import Contains, DoesNotContain, ItemMatch

# Check if the "response" column contains any of the specified keywords
contains_feature = Contains(
    column_name="response",
    items=["error", "warning"],
    case_sensitive=False,
    mode="any"
)

# Check that "response" does not contain all forbidden terms
not_contains_feature = DoesNotContain(
    column_name="response",
    items=["confidential", "secret"],
    case_sensitive=True,
    mode="all"
)

# Check if words from column B appear in the text of column A
item_match = ItemMatch(
    columns=["generated_text", "expected_keywords"],
    case_sensitive=False,
    mode="all"
)

Related Pages

Page Connections

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