pub enum ResponseFormat {
Text,
JsonObject,
JsonSchema {
schema: Value,
name: String,
strict: bool,
},
}Expand description
Desired output shape for an LLM call.
Default Text matches the historical free-form text behaviour. JsonObject
constrains output to syntactically valid JSON with no schema enforcement;
JsonSchema adds strict-shape enforcement when the provider supports it.
Message::extract_json::<T>() is the recommended way to parse the resulting
assistant message back into a typed value — it handles both native JSON-mode
output (text content is JSON) and tool-call emulation (arguments JSON of a
well-known synthetic tool) uniformly.
Variants§
Text
Free-form text. Default; providers ignore the field entirely.
JsonObject
Constrain output to valid JSON; no schema enforcement.
Maps to:
- OpenAI Completions / Responses / Azure:
response_format: { type: "json_object" } - Google GenAI / Vertex:
responseMimeType: "application/json" - Anthropic / Bedrock-Anthropic: a synthetic
respond_jsontool with an empty-shape schema; the LLM is forced to call it with its answer - Bedrock non-Anthropic: not supported — provider returns
SchemaMismatch
JsonSchema
Strict JSON Schema enforcement. The schema is forwarded to the provider when supported natively; otherwise emulated via tool-call shape (Anthropic).
Fields
Trait Implementations§
Source§impl Clone for ResponseFormat
impl Clone for ResponseFormat
Source§fn clone(&self) -> ResponseFormat
fn clone(&self) -> ResponseFormat
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more