yera.dsl.control

Module containing Yera DSL constructs for control flow using LLMs.

Symbols

class Condition — Represents a boolean condition with instruction.
def condition — Use the active LLM to evaluate a boolean condition.
class Option — Represents a single option in a selection.
def option — Create an Option instance.
def select — Use the active LLM to choose between a set of options.

Condition

Inherits: Struct

Represents a boolean condition with instruction.

Fields

condition
type: bool (required)

Whether the condition holds or not

condition

condition(
    instruction: str,
    on_wire: bool = False,
    **kwargs,
) → bool

Use the active LLM to evaluate a boolean condition.

Parameters

instruction
type: str

Instruction text describing what the condition checks.

on_wire
type: bool = False

Whether the field should be included in LLM context (default: False).

**kwargs
type: _GenerationOption

Additional keyword arguments passed to the model fill method.

Returns

type: bool

Boolean value representing whether the condition holds.

Examples

Check a fact established in the conversation without retaining the generated decision:

python
import yera as yr

is_weekend_trip = yr.condition(
    "Is the requested journey shorter than three days?",
    on_wire=False,
    temperature=0,
)

Option

Represents a single option in a selection.

Fields

label
type: str (required)

The label shown for the option.

description
type: str | None = None

Optional detailed description of the option.

Methods


Option.__init__

__init__(
    label: str,
    description: str | None = None,
) → None

option

option(
    label: str,
    description: str | None = None,
) → Option

Create an Option instance.

Parameters

label
type: str

The visible label for the option.

description
type: str | None = None

Optional descriptive text.

Returns

type: Option

An Option instance with given label and description.

Examples

Describe possible destinations for a day trip:

python
import yera as yr

museum = yr.option(
    "Museum",
    "Spend the afternoon viewing art.",
)
park = yr.option(
    "Park",
    "Walk outdoors if the weather is fine.",
)

select

select(
    *options,
    instruction: str | None = None,
    name: str = 'Selection',
    on_wire: bool = False,
    **kwargs,
) → str

Use the active LLM to choose between a set of options.

Parameters

*options
type: str | Option = ()

One or more option labels or Option instances.

instruction
type: str | None = None

Instruction text to describe the purpose of this selection.

name
type: str = 'Selection'

Name for the generated class (default: "Selection").

on_wire
type: bool = False

Whether the field should be included in the LLM context (default: False).

**kwargs
type: _GenerationOption

Additional keyword arguments passed to the model fill method.

Returns

type: str

The selected option

Raises

ValueError

If fewer than two options are provided or labels are not unique.

Examples

Ask the model to classify a message without retaining the decision in the conversation:

python
import yera as yr

route = yr.select(
    yr.option("question", "The user wants information."),
    yr.option("chat", "The user is making conversation."),
    instruction="Classify the latest message.",
    on_wire=False,
)