Implementation:Evidentlyai Evidently Legacy Text Length Feature
| Knowledge Sources | |
|---|---|
| Domains | NLP, Feature Engineering, Text Analysis |
| Last Updated | 2026-02-14 12:00 GMT |
Overview
The TextLength class is a generated feature that computes the character length of each text value in a specified column.
Description
TextLength extends ApplyColumnGeneratedFeature and produces a ColumnType.Numerical output. For each row, the apply method returns the result of len(value) on the text content. If the value is None or NaN, it returns 0. The generated column is named using the template "Text Length for {column_name}".
This is one of the simplest text feature extractors in the legacy features module, providing a basic quantitative signal about text volume.
Usage
Use this feature when you need to monitor or analyze the length of text data, such as tracking whether model input or output lengths drift over time, or as an auxiliary feature for quality checks in reports.
Code Reference
Source Location
- Repository: Evidentlyai_Evidently
- File:
src/evidently/legacy/features/text_length_feature.py
Signature
class TextLength(ApplyColumnGeneratedFeature):
class Config:
type_alias = "evidently:feature:TextLength"
__feature_type__: ClassVar = ColumnType.Numerical
display_name_template: ClassVar = "Text Length for {column_name}"
column_name: str
def __init__(self, column_name: str, display_name: Optional[str] = None): ...
def apply(self, value: Any) -> int: ...
Import
from evidently.legacy.features.text_length_feature import TextLength
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| column_name | str | Yes | Name of the text column to compute length for |
| display_name | Optional[str] | No | Custom display name for the generated feature column |
Outputs
| Name | Type | Description |
|---|---|---|
| Text length | int | Number of characters in the text value. Returns 0 for None or NaN values. |
Usage Examples
from evidently.legacy.features.text_length_feature import TextLength
# Create a text length feature for the "description" column
text_length_feature = TextLength(column_name="description")
# With a custom display name
text_length_feature = TextLength(column_name="comment", display_name="Comment Character Count")