Skip to main content
A Predict takes a signature and actually calls the LM. It’s the bridge between your type definitions and real LLM inference. Under the hood, it uses an adapter to format prompts and parse responses.

Basic usage

The turbofish ::<QA> tells Rust which signature you’re using. The macro generates QAInput from your #[input] fields.

Creating predictors

Simple

With instruction override

This overrides the docstring instruction on the signature.

With demos (few-shot)

Demos are Example<S> — typed input/output pairs. They become few-shot examples in the prompt.

With tools

Calling predictors

.call() returns Result<Predicted<Output>, PredictError>. Predicted<O> wraps the output with call metadata and implements Deref<Target = O>, so you access fields directly:

Accessing metadata

For token usage, raw response text, or per-field parse details, use .metadata():

CallMetadata fields

Error handling

Predict implements Module

Predict<S> implements the Module trait with typed associated types:
This means predictors work with optimizers and can be nested in custom modules.

Multiple predictors in a pipeline

Prompting strategies

Instead of manually adding fields for chain-of-thought reasoning, use library modules that augment any signature:
  • ChainOfThought<S> — adds a reasoning field, accessible via result.reasoning
  • ReAct<S> — adds tool-calling with an action/observation loop
See Modules for details.