Implementation:Evidentlyai Evidently Legacy Contains Link Feature
| Knowledge Sources | |
|---|---|
| Domains | ML Monitoring, NLP, Text Quality |
| Last Updated | 2026-02-14 12:00 GMT |
Overview
Detects whether a text column contains URLs/links by parsing each word with Python's urlparse and checking for valid scheme and netloc components.
Description
The ContainsLink class extends ApplyColumnGeneratedFeature to produce a categorical feature indicating whether each text value contains at least one valid URL. The detection logic works by splitting the text into whitespace-delimited words and passing each word through urllib.parse.urlparse. A word is considered a valid link if both the scheme (e.g., "http", "https") and netloc (e.g., "example.com") components are present.
The feature type is Categorical (returning True/False), and the default display name follows the template "{column_name} contains link". Null or NaN values return 0 (falsy).
This is a lightweight, dependency-free link detection approach that does not require external NLP libraries -- it relies solely on Python's standard library urllib.parse module.
Usage
Use this feature when monitoring text outputs for the presence of URLs, such as checking whether LLM-generated responses contain links (which may be undesirable in certain contexts) or ensuring that text fields expected to contain references actually include URLs.
Code Reference
Source Location
- Repository: Evidentlyai_Evidently
- File:
src/evidently/legacy/features/contains_link_feature.py
Signature
class ContainsLink(ApplyColumnGeneratedFeature):
class Config:
type_alias = "evidently:feature:ContainsLink"
__feature_type__: ClassVar = ColumnType.Categorical
display_name_template: ClassVar = "{column_name} contains link"
def __init__(self, column_name: str, display_name: Optional[str] = None): ...
def apply(self, value: Any): ...
Import
from evidently.legacy.features.contains_link_feature import ContainsLink
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| column_name | str | Yes | The name of the text column to check for links. |
| display_name | Optional[str] | No | Custom display name for the feature. Defaults to "{column_name} contains link". |
Outputs
| Name | Type | Description |
|---|---|---|
| return | pd.DataFrame | A single-column DataFrame with boolean values (True if a link is found, False/0 otherwise). |
Usage Examples
from evidently.legacy.features.contains_link_feature import ContainsLink
# Check if the "response" column contains links
link_feature = ContainsLink(column_name="response")
# With a custom display name
link_feature = ContainsLink(
column_name="assistant_reply",
display_name="Reply Contains URL",
)
# The apply method can be used directly for testing
link_feature.apply("Visit https://example.com for details") # Returns True
link_feature.apply("No links here") # Returns False
link_feature.apply(None) # Returns 0
Related Pages
- Environment:Evidentlyai_Evidently_Python_Core_Environment
- Evidentlyai_Evidently_Legacy_Generated_Features - Base class ApplyColumnGeneratedFeature that ContainsLink extends.
- Evidentlyai_Evidently_Legacy_OOV_Words_Feature - Another text quality feature using the same ApplyColumnGeneratedFeature pattern.