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

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

Overview

This module provides two generated feature classes -- BeginsWith and EndsWith -- for checking whether text values in a column start or end with a specified substring.

Description

Both classes extend GeneratedFeature and produce ColumnType.Categorical (boolean) outputs.

BeginsWith checks whether each text value in the specified column starts with a given prefix. EndsWith checks whether each text value ends with a given suffix. Both support an optional case_sensitive flag; when set to False, both the column data and the substring are case-folded before comparison using Python's str.casefold() method.

The feature column names are constructed as {column_name}.{prefix/suffix}.{case_sensitive}, and the display names follow the patterns "Text Begins with [{prefix}] for {column_name}" and "Text Ends with [{suffix}] for {column_name}" respectively.

Usage

Use these features when you need to identify or filter text entries based on their prefixes or suffixes. Common use cases include verifying that generated text follows expected formatting patterns, detecting specific greeting phrases, or checking for particular file extensions or URL patterns in text data.

Code Reference

Source Location

Signature

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

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

Import

from evidently.legacy.features.text_part_feature import BeginsWith
from evidently.legacy.features.text_part_feature import EndsWith

I/O Contract

Inputs (BeginsWith)

Name Type Required Description
column_name str Yes Name of the text column to check
prefix str Yes The prefix string to check for at the beginning of text values
case_sensitive bool No Whether matching is case-sensitive (default: True)
display_name Optional[str] No Custom display name for the generated feature column

Inputs (EndsWith)

Name Type Required Description
column_name str Yes Name of the text column to check
suffix str Yes The suffix string to check for at the end of text values
case_sensitive bool No Whether matching is case-sensitive (default: True)
display_name Optional[str] No Custom display name for the generated feature column

Outputs

Name Type Description
generated feature column bool True if the text starts with (or ends with) the specified substring, False otherwise

Usage Examples

from evidently.legacy.features.text_part_feature import BeginsWith, EndsWith

# Check if responses begin with a greeting
begins_feature = BeginsWith(
    column_name="response",
    prefix="Hello",
    case_sensitive=False
)

# Check if URLs end with a specific extension
ends_feature = EndsWith(
    column_name="url",
    suffix=".html",
    case_sensitive=True
)

Related Pages

Page Connections

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