Counting visitors…
Browse all docs
Start · 9Find your path through RunifoldLearn Runifold in 45 minutesUnderstand the complete Runifold platformYour first trustworthy runChoose the right execution APIChoose crates and Cargo featuresBuild common Runifold applicationsRunifold frequently asked questionsTroubleshoot Runifold applications
Execution kernel · 7Understand RunContextCoordinate external effects safelyBound work with budgets and cancellationHandle errors and retries safelyEvents, journals, and execution evidenceDesign capability-safe executionRecover safely from checkpoints
Models & providers · 7Route across models without duplicate outputChoose and configure a providerUse the provider-neutral model protocolBuild on the Provider Runtime contractUse OpenAI control-plane and Realtime APIsTest and benchmark provider adaptersSet up OpenAI, Anthropic, Gemini, and Ollama
Agents · 7Build and configure an AgentGive an Agent typed toolsAdd conversations and semantic memoryDelegate to child Agents safelyReturn structured Rust valuesStream without losing semanticsGround an Agent with retrieval
Durable workflows · 7Compose deterministic workflowsMake workflows durableOperate durable workflow workersCoordinate timers, signals, and durable waitsRun multi-tenant workflow infrastructureRun parallel branches and safe racesVersion and evolve durable workflows
Integrations · 7Connect through MCPChoose stores and persistence boundariesExpose durable work through MCP TasksBuild and evaluate retrieval pipelinesUse MCP Resources, Prompts, and SamplingCache MCP responses without crossing authorityDeploy Runifold in a Rust web service
Quality & operations · 10Test without the networkEvaluate quality and prevent regressionsObserve the complete run treeRun safely in browsers and at the edgeRead reliability claims preciselyRun reproducible evaluations in CIOperate Runifold with SLOsGovern Task retention and deletionArchive audit evidence to S3-compatible WORM storageManage compatibility and trusted releases
Docs/Build agents
NEW TO RUNIFOLD?Build the complete mental model in 45 minutes
Build agents

Return structured Rust values

Request schema-backed model output and handle provider capability differences explicitly.

Practical guide·8 min

Define the output

Use a Rust type as the contract between the model and the rest of your application. Derive both Deserialize and JsonSchema; keep fields concrete and document choices that are easy to confuse.

cargo add serde --features derive
cargo add schemars
use runifold::JsonSchema;
use serde::Deserialize;
 
#[derive(Debug, Deserialize, JsonSchema)]
struct Triage {
    category: String,
    urgent: bool,
    explanation: String,
}

Avoid embedding business side effects in deserialization. Validate domain rules after decoding.

Build a structured Agent

build_structured::<T>() attaches the schema to the request and returns a typed Agent. The result preserves both the decoded value and the complete canonical outcome.

let agent = runtime
    .agent("triage")
    .system("Classify the request. Keep the explanation short.")
    .build_structured::<Triage>("triage_result")?;
 
let result = agent.run("Payment failed twice", &run).await?;
println!("{:?}", result.output);
println!("turns: {}", result.outcome.turns);

Use an explicit RunContext in production so the same call also carries budgets, authority, cancellation, and observability.

Validation and errors

There are two separate failure classes:

  • the provider can reject or ignore the requested output format;
  • the returned JSON can fail local deserialization or domain validation.

Treat both as data-quality failures, not as permission to silently fall back to unvalidated text. Log the response ID and model identity, but do not log sensitive payloads by default.

Provider support

Structured output is a capability contract. Some models support strict schema enforcement, others support JSON mode only, and compatible endpoints may advertise more than they enforce. Test the exact provider, model, and feature combination you deploy.

When strictness is required, configure the feature policy to fail closed. When degradation is acceptable, make the fallback visible in product behavior and metrics.