Expand description
Native Rust predict engine for structured LLM prediction.
Provides core types for building structured input/output contracts for language model calls, formatting prompts, parsing responses, and composing multi-step LLM programs with introspectable, serializable state.
§Prompt visibility for debugging
ChatAdapter::format emits the fully
assembled prompt at TRACE on the target
typesayer::adapter::chat::messages — a signature shorthand
("inputs -> outputs") plus messages_json, the provider-agnostic
Vec<Message> serialized to JSON (the [[ ## field ## ]] envelope, demo
turns, and cache-breakpoint markers). Off by default; an operator opts in:
- Standalone binaries / examples (env filter reads
RUST_LOG):RUST_LOG=typesayer::adapter::chat::messages=trace - Applications with a broader filter can pass a complete directive:
RUST_LOG="warn,typesayer=info,typesayer::adapter::chat::messages=trace"
Prompts can contain sensitive user data, so
this is TRACE-gated and intended for … 2>&1 | tee inspection — never
enable it in production log shipping.
§Quick Start
use std::{collections::BTreeMap, sync::Arc};
use modelplease::{DummyLM, ModelId};
use typesayer::{ChatAdapter, Context, Predict};
use typesayer_types::{FieldDef, FieldType, FieldValue, Signature};
let sig = Signature::builder("Answer the question.")
.input(FieldDef::input("question", FieldType::String, "The question"))
.output(FieldDef::output("answer", FieldType::String, "The answer"))
.build()?;
let lm = DummyLM::sequential(vec!["[[ ## answer ## ]]\nParis\n[[ ## completed ## ]]".into()]);
let ctx = Context {
provider: Arc::new(lm),
model: ModelId::new("test"),
adapter: Arc::new(ChatAdapter::default()),
};
let prediction = Predict::new(sig)
.call(
&BTreeMap::from([("question".into(), FieldValue::Str("Capital of France?".into()))]),
&ctx,
)
.await?;
assert_eq!(prediction.get::<String>("answer")?, "Paris");§Modules
Core types (PredictError, Result, FieldType, FieldDef, FieldKind,
FieldValue, ObjectField, Signature, SignatureBuilder) live in the
typesayer-types crate and are re-exported here.
format—FieldSerializer,FieldDeserializer,JsonFieldSerializer,JsonFieldDeserializeradapter—Adaptertrait,ChatAdapter,Demoprediction—Prediction,TryFromFieldValuecontext—Contextpredict—Predictexample—Example(flat fields + input key separation)module—Moduletrait (composition, introspection, state persistence)state— module save/load helpers
Structs§
- AwsAccount
Id - A 12-digit AWS account id. Used as the optional
bucket_owneronMediaSource::S3for cross-accountS3Locationreferences. - Bootstrap
FewShot - Automatic few-shot demo selection via teacher-model bootstrapping.
- Chat
Adapter ChatAdapterformats prompts using[[ ## field_name ## ]]section delimiters.- Compile
Request - Per-call inputs for
Optimizer::compile. - Context
- Holds the language model provider, target model, and adapter for prediction calls.
- Demo
- A few-shot demonstration example with typed values.
- Evaluate
Config - Configuration for the evaluation runner.
- Evaluation
Result - The result of an evaluation run.
- Example
- A labeled data point with a declared set of input keys.
- Execution
Trace - An ordered collection of trace entries from a module’s forward pass.
- Field
Def - A top-level field definition within a
Signature. - Https
Url - A URL pinned to the
https://scheme. - Json
Field Deserializer - JSON-based field deserializer.
- Json
Field Serializer - JSON-based field serializer.
- Json
Schema Definition - A JSON Schema definition for constructing a
Signatureat runtime. - Labeled
FewShot - Simple few-shot demo assignment from labeled training data.
- MIPROv2
MIPROv2optimizer — joint instruction and demo optimization.- Media
Type - An RFC 6838 media type / MIME (
type/subtype[;parameters]). - Message
- A single message in an LM conversation.
- Mipro
Compile Request - Per-call inputs for
MIPROv2::compile_mipro. - Mipro
Config - Pure-value tuning for
MIPROv2. - Mipro
Deps - Behavior-bearing dependencies for
MIPROv2. The metric closure is the only thing here — every other knob lives onMiproConfig. - ModelId
- Provider model identifier (e.g.
"claude-sonnet-4-6","gpt-4o-mini"). Wraps an arbitraryStringso it cannot be passed where anApiKeyis expected. - Object
Field - A field within an
Objecttype. - OneOf
Discriminator - Discriminator hint for a tagged
OneOf. - Predict
- Orchestrates a structured prediction: format a prompt from a signature, call a language model, and parse the response into typed fields.
- Prediction
- The result of a
Predict::call()invocation. - Progress
- A progress update from an optimizer.
- Provider
File Id - An opaque, provider-issued file identifier (Anthropic Files API,
OpenAIFiles API). - S3Uri
- A canonical AWS S3 URI:
s3://<bucket>/<key>. - Signature
- A signature defines the input/output contract for a prediction.
- Signature
Builder - Builder for constructing a
Signature. - Trace
Entry - A single predictor invocation record.
- Variant
Arm - One arm of a
OneOforAnyOf.
Enums§
- Auto
Mode - Auto mode presets matching
DSPyconventions. - Cache
Placement - Where
ChatAdapter::formatinserts the static-prefix cache breakpoint. - Capability
Error - Reasons a request can fail capability validation, by precision.
- Content
Part - A single content part within a message.
- Field
Kind - Whether a field is an input or output of a signature.
- Field
Type - The type of a field in a signature.
- Field
Value - A typed value extracted from an LM completion or supplied as input.
- Media
Kind - Bucket for media content parts.
- Media
Source - Where the bytes of one media content part come from.
- Predict
Error - Errors that can occur in predict operations.
- Role
- Message role in a conversation.
- Source
Kind - Discriminant for
MediaSourcevariants, suitable for use inenumset::EnumSet-backed capability masks (e.g.MediaSupport.sources).
Traits§
- Adapter
- Converts between signatures with typed input values and LM message sequences.
- Field
Deserializer - Deserializes raw text from a completion into a
FieldValue. - Field
Serializer - Serializes a
FieldValueinto text for inclusion in a prompt. - Module
- A composable unit of LLM-powered logic.
- Optimizer
- A prompt optimizer that improves a module’s performance by modifying its predictors’ demos, instructions, or both.
- TryFrom
Field Value - Convert a
FieldValuereference into a concrete Rust type.
Functions§
- evaluate
- Evaluate a module on a dataset using a metric function.
- extract_
description - Extract a description from a field schema, with enum value appending and JSON Schema constraint-keyword annotations.
- field_
type_ from_ schema - Convert a single JSON Schema definition into a
FieldType. - is_
field_ required Deprecated - Check if a field schema has
required: false(non-standard per-field boolean). - signature_
from_ json_ schema - Construct a
Signaturefrom JSON Schema definitions at runtime.
Type Aliases§
- Metric
Fn - A metric function that scores a prediction against an expected example.
- Progress
Fn - A progress callback invoked during optimization.
- Result
- A specialized
Resulttype for predict operations.