Skip to content

select()

Select one or more options from a given list or type representing a set of options.

API Reference
select()

Synchronously select one or more options from the given target.

Parameters:

Name Type Description Default
target Any | List[Any]

The options to select from. Can be: - A list of values or types - A Literal[...] type - An Enum subclass - A Union[..., ...] type

required
context ContextType | List[ContextType] | None

Optional additional context or conversation history. Defaults to None.

None
multi_label bool

When True, return a list of selected objects; otherwise return a single selected object. Defaults to False.

False
literal bool

When True and supported by the options, use Literal[...] for the selection field instead of indices. Defaults to True.

True
include_reason bool

Reserved flag to include a textual reason field in the intermediate structured output (not exposed in the final result). Defaults to False.

False
confidence bool

When True, enable log-probability based confidence scoring. Defaults to False.

False
model ModelParam

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

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

Model settings to pass to the operation (e.g., temperature). 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 (e.g., pydantic_ai.RunContext) for this operation. Defaults to None.

None
usage_limits PydanticAIUsageLimits | None

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

None
stream bool

When True, return a stream wrapper that exposes the underlying model stream and remaps the final result to the selected object(s). Defaults to False.

False

Returns:

Type Description
Result[Output] | _SelectionStreamWrapper

Result[Output] | _SelectionStreamWrapper: A Result whose output is either the selected object or a list of selected objects. When include_reason is True, the output is a dict with keys selection and reason. For streaming, the wrapper preserves the same final semantics.

aselect()

Asynchronously select one or more options from the given target.

Parameters:

Name Type Description Default
target Any | List[Any]

The options to select from. Can be: - A list of values or types - A Literal[...] type - An Enum subclass - A Union[..., ...] type

required
context ContextType | List[ContextType] | None

Optional additional context or conversation history. Defaults to None.

None
multi_label bool

When True, return a list of selected objects; otherwise return a single selected object. Defaults to False.

False
literal bool

When True and supported by the options, use Literal[...] for the selection field instead of indices. Defaults to True.

True
include_reason bool

Reserved flag to include a textual reason field in the intermediate structured output (not exposed in the final result). Defaults to False.

False
confidence bool

When True, enable log-probability based confidence scoring. Defaults to False.

False
model ModelParam

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

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

Model settings to pass to the operation (e.g., temperature). 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 (e.g., pydantic_ai.RunContext) for this operation. Defaults to None.

None
usage_limits PydanticAIUsageLimits | None

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

None
stream bool

When True, return a stream wrapper that exposes the underlying model stream and remaps the final result to the selected object(s). Defaults to False.

False

Returns:

Type Description
Result[Output] | _SelectionStreamWrapper

Result[Output] | _SelectionStreamWrapper: A Result whose output is either the selected object or a list of selected objects. When include_reason is True, the output is a dict with keys selection and reason. For streaming, the wrapper preserves the same final semantics.


Overview

The select() semantic operation is used to select one more options from a given list or type representing a set of options that a model can choose from.

Single Classification
from zyx import select


result = select(
    target=["red", "green", "blue"], # (1)!
    context="What is the color of the sky?",
)


print(result.output)
"""
"blue"
"""
  1. The target parameter when using select, can be a list of any compatible types (str, int, BaseModel, etc.), or a Literal[...], Enum, or Union[..., ...] type.
Single Classification
from zyx import aselect


async def main():
    result = await aselect(
        target=["red", "green", "blue"],
        context="What is the color of the sky?",
    )

Multi-Label Selection

When running this operation, you can choose between setting the multi_label parameter to True or False, which allows for single or multiple selection respectively.

Multi-Label Selection
from zyx import select


result = select(
    target=["red", "black", "blue", "yellow", "purple"],
    context="What colors make green?",
    multi_label=True,
)


print(result.output)
"""
["blue", "yellow"]
"""

Reasoning

Optionally, you can set the include_reason parameter to True, to allow the model to provide a textual reason for it's selection.

Including Reasoning
from zyx import select


result = select(
    ["positive", "negative"],
    context="This produce is okay.",
    include_reason=True,
)


print(result.output.selection)
print(result.output.reason)
"""
positive
The statement indicates that the produce is acceptable or satisfactory.
"""