pub struct ResponseFormat {
pub name: String,
pub schema: Value,
pub strict: bool,
}Expand description
A request to constrain the model’s output to a named JSON schema.
Construct with ResponseFormat::from_type from any StructuredOutput
type, or manually from a raw schema + name via ResponseFormat::new.
Passed to the provider via RequestOptions.
Fields§
§name: StringLogical name for the schema.
Copied from StructuredOutput::name when constructed via
from_type. Used as the OpenAI json_schema.name
and the Anthropic forced-tool name. Must match ^[a-zA-Z0-9_-]+$.
schema: ValueThe JSON Schema the model’s output must satisfy.
Injected into the provider request verbatim: OpenAI emits it as
response_format.json_schema.schema; Anthropic uses it as the
forced tool’s input_schema.
strict: boolWhether to enforce the schema server-side (“strict” mode).
When true (the default), OpenAI guarantees the output conforms to
the schema. Providers that lack strict mode (Anthropic tool-forcing)
ignore this flag.
Implementations§
Source§impl ResponseFormat
impl ResponseFormat
Sourcepub fn from_type<T: StructuredOutput>() -> Self
pub fn from_type<T: StructuredOutput>() -> Self
Build a ResponseFormat from a StructuredOutput type.
§Example
use loopctl::structured::{ResponseFormat, StructuredOutput};
let rf = ResponseFormat::from_type::<MyOutput>();
assert_eq!(rf.name, MyOutput::name());
assert_eq!(rf.schema, MyOutput::schema());
assert!(rf.strict);Sourcepub fn new(name: impl Into<String>, schema: Value) -> Self
pub fn new(name: impl Into<String>, schema: Value) -> Self
Build a ResponseFormat from raw parts.
Use this when the schema is constructed dynamically (e.g. at runtime
from config or a database) rather than from a static type. For the
common case of deriving the format from a StructuredOutput type,
prefer from_type.
Sets strict: true by default — the model is constrained server-side
where supported (OpenAI strict mode, Anthropic ignores the flag).
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