pub struct StructuredOutputFormat {
pub name: String,
pub description: Option<String>,
pub schema: Option<Value>,
pub strict: Option<bool>,
}
Expand description
Defines rules for structured output responses based on OpenAI’s structured output requirements. Individual providers may have additional requirements or restrictions, but these should be handled by each provider’s backend implementation.
If you plan on deserializing into this struct, make sure the source text has a "name"
field, since that’s technically the only thing required by OpenAI.
§Example
use llm::chat::StructuredOutputFormat;
use serde_json::json;
let response_format = r#"
{
"name": "Student",
"description": "A student object",
"schema": {
"type": "object",
"properties": {
"name": {
"type": "string"
},
"age": {
"type": "integer"
},
"is_student": {
"type": "boolean"
}
},
"required": ["name", "age", "is_student"]
}
}
"#;
let structured_output: StructuredOutputFormat = serde_json::from_str(response_format).unwrap();
assert_eq!(structured_output.name, "Student");
assert_eq!(structured_output.description, Some("A student object".to_string()));
Fields§
§name: String
Name of the schema
description: Option<String>
The description of the schema
schema: Option<Value>
The JSON schema for the structured output
strict: Option<bool>
Whether to enable strict schema adherence
Trait Implementations§
Source§impl Clone for StructuredOutputFormat
impl Clone for StructuredOutputFormat
Source§fn clone(&self) -> StructuredOutputFormat
fn clone(&self) -> StructuredOutputFormat
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source
. Read moreSource§impl Debug for StructuredOutputFormat
impl Debug for StructuredOutputFormat
Source§impl<'de> Deserialize<'de> for StructuredOutputFormat
impl<'de> Deserialize<'de> for StructuredOutputFormat
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
Source§impl PartialEq for StructuredOutputFormat
impl PartialEq for StructuredOutputFormat
Source§impl Serialize for StructuredOutputFormat
impl Serialize for StructuredOutputFormat
impl StructuralPartialEq for StructuredOutputFormat
Auto Trait Implementations§
impl Freeze for StructuredOutputFormat
impl RefUnwindSafe for StructuredOutputFormat
impl Send for StructuredOutputFormat
impl Sync for StructuredOutputFormat
impl Unpin for StructuredOutputFormat
impl UnwindSafe for StructuredOutputFormat
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read more