Bridle
Reference

Primitives

step, branch, loop. Signatures, parameters, returns, raises.

Three functions, all in bridle. Each returns a Call typed as the value it will resolve to.

step

bridle.step(
    prompt: str,
    *,
    schema: type[T],
    context: Any = None,
    tools: Sequence[Tool] = (),
    system: str | None = None,
    max_turns: int = 50,
    max_schema_retries: int = 3,
    label: str | None = None,
) -> T

Run one unit of judgment. The model is given the prompt (and optional context), the supplied tools, and a synthetic __bridle_return__ tool whose schema matches schema. The step ends when the model calls __bridle_return__ with arguments that satisfy the schema.

ParameterTypeDescription
promptstrThe instruction the model receives.
schematype[T]Pydantic model, bare type, enum, or Literal.
contextAnyJSON-serializable extra context appended to the prompt.
toolsSequence[Tool]Tools the model may call during the step.
systemstr | NoneSystem prompt override. Resolution: per-call > per-agent (@agent(system=...)) > the loop's built-in default.
max_turnsintCaps total model turns. Default 50.
max_schema_retriesintCaps invalid structured-output attempts before SchemaSatisfactionError. Default 3.
labelstr | NoneTrace label. Defaults to the prompt.

Returns: a Call annotated as T. Resolves on first read to the typed value.

Raises during resolution:

branch

bridle.branch(
    prompt: str,
    *,
    schema: type[T] = bool,
    context: Any = None,
    label: str | None = None,
) -> T

A step constrained to one typed decision — no tools.

ParameterTypeDescription
promptstrThe decision to make.
schematype[T]Defaults to bool. Pass an Enum or Literal[...] for multi-way.
contextAnyJSON-serializable extra context.
labelstr | NoneTrace label. Defaults to the prompt.

Returns: a Call annotated as T. Resolves on truthiness or read.

Raises during resolution: same as step, minus ToolExecutionError.

Notes: shares step's evaluator with Call.kind == "branch" so the trace records it distinctly.

loop

bridle.loop(
    prompt: str,
    *,
    schema: type[T],
    until: Callable[[list[T]], bool],
    context: Any = None,
    tools: Sequence[Tool] = (),
    max_iterations: int = 32,
    label: str | None = None,
) -> list[T]

Repeat an inner step until until(accumulator) returns True. Each iteration's context is {"original_context": context, "previous_results": [...], "iteration": N}.

ParameterTypeDescription
promptstrThe instruction for each iteration.
schematype[T]The shape of each value produced.
untilCallable[[list[T]], bool]Pure-Python predicate over the accumulator.
contextAnyJSON-serializable shared context.
toolsSequence[Tool]Tools available in each iteration.
max_iterationsintHard cap. Default 32. Must be positive.
labelstr | NoneTrace label.

Returns: a Call annotated as list[T].

Raises during resolution:

  • LoopExhaustedError — predicate never returned True before max_iterations. Carries the partial accumulator.
  • Any error the inner step would raise.

On this page