Skip to content

expr()

Run simple Pythonic expressions such as ==, if x in y, ... operations against a given source.

API Reference
expr()

Create an Expressions instance for semantic expression evaluation.

Parameters:

Name Type Description Default
source SourceParam | None

The source value to evaluate expressions against. Defaults to None.

None
context ContextType | List[ContextType] | None

Optional context or conversation history. Defaults to None.

None
model ModelParam

The model to use for evaluation. Defaults to "openai:gpt-4o-mini".

'openai:gpt-4o-mini'
model_settings PydanticAIModelSettings | None

Model settings (e.g., temperature). Defaults to None.

None
attachments AttachmentType | List[AttachmentType] | None

Attachments provided to the agent. Defaults to None.

None
instructions PydanticAIInstructions | None

Additional instructions/hints for the model. Defaults to None.

None
tools ToolType | List[ToolType] | None

List of tools available to the model. Defaults to None.

None
deps Deps | None

Optional dependencies for this operation. Defaults to None.

None
usage_limits PydanticAIUsageLimits | None

Usage limits (token/request) configuration. Defaults to None.

None

Returns:

Name Type Description
Expressions Expressions

An Expressions instance that can be used for semantic expression evaluation.

Example
from zyx.operations.expressions import expr

# Evaluate boolean expression
result = bool(expr("The weather is sunny today"))

# Evaluate semantic equality
result = expr("It's a beautiful day") == "nice weather"

# Check if content contains a concept
result = "happiness" in expr("I feel great today")

Overview

The expr() semantic operation is a simple operation that allows you to use Pythonic dunder methods or expressions to perform evaluations against a given source.

Unlike all other semantic operations, the expr() operation cannot be asynchronously and has a locked target type, based on the expression being used.

Using expr()
from zyx import expr

if "hate speech" in expr("you suck"):
    print("The statement contains hate speech.")
else:
    print("The statement does not contain hate speech.")
"""
The statement contains hate speech.
"""

Supported Expressions

Flip through the following table to get a better idea of the various expressions that can be used with expr().

==
from zyx import expr

if expr("the weather is sunny today") == "positive":
    print("positive")
"""
positive
"""
in
from zyx import expr

if "hate speech" in expr("you suck"):
    print("The statement contains hate speech.")
"""
The statement contains hate speech.
"""
contains
from zyx import expr

if expr("he has 43 active issues") > 30:
    print("He has more than 30 active issues.")
"""
He has more than 30 active issues.
"""