pub struct StructuredOutputSchema<T> {
pub tool_name: String,
pub tool_description: String,
pub schema: ObjectJsonSchema,
pub strict: Option<bool>,
/* private fields */
}Expand description
Schema for structured output using serde.
This schema parses model output into a typed Rust struct using serde. It supports multiple output modes (tool, native, prompted, text).
§Example
use serdes_ai_output::StructuredOutputSchema;
use serdes_ai_tools::ObjectJsonSchema;
use serde::Deserialize;
#[derive(Deserialize)]
struct Person {
name: String,
age: u32,
}
let schema = ObjectJsonSchema::new()
.with_property("name", serdes_ai_tools::PropertySchema::string("Name").build(), true)
.with_property("age", serdes_ai_tools::PropertySchema::integer("Age").build(), true);
let output_schema: StructuredOutputSchema<Person> = StructuredOutputSchema::new(schema);Fields§
§tool_name: StringTool name when using tool mode.
tool_description: StringTool description.
schema: ObjectJsonSchemaJSON schema for the output.
strict: Option<bool>Whether to use strict mode (for OpenAI).
Implementations§
Source§impl<T: DeserializeOwned + Send + Sync> StructuredOutputSchema<T>
impl<T: DeserializeOwned + Send + Sync> StructuredOutputSchema<T>
Sourcepub fn new(schema: ObjectJsonSchema) -> Self
pub fn new(schema: ObjectJsonSchema) -> Self
Create a new structured output schema.
Sourcepub fn with_tool_name(self, name: impl Into<String>) -> Self
pub fn with_tool_name(self, name: impl Into<String>) -> Self
Set the tool name.
Sourcepub fn with_description(self, desc: impl Into<String>) -> Self
pub fn with_description(self, desc: impl Into<String>) -> Self
Set the tool description.
Sourcepub fn with_strict(self, strict: bool) -> Self
pub fn with_strict(self, strict: bool) -> Self
Set strict mode (for OpenAI structured outputs).
Sourcepub fn with_mode(self, mode: OutputMode) -> Self
pub fn with_mode(self, mode: OutputMode) -> Self
Set the preferred output mode.
Trait Implementations§
Source§impl<T: Clone> Clone for StructuredOutputSchema<T>
impl<T: Clone> Clone for StructuredOutputSchema<T>
Source§fn clone(&self) -> StructuredOutputSchema<T>
fn clone(&self) -> StructuredOutputSchema<T>
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<T: Debug> Debug for StructuredOutputSchema<T>
impl<T: Debug> Debug for StructuredOutputSchema<T>
Source§impl<T: DeserializeOwned + Send + Sync + 'static> IntoOutputSpec<T> for StructuredOutputSchema<T>
impl<T: DeserializeOwned + Send + Sync + 'static> IntoOutputSpec<T> for StructuredOutputSchema<T>
Source§fn into_output_spec(self) -> OutputSpec<T>
fn into_output_spec(self) -> OutputSpec<T>
Convert into an output spec.
Source§impl<T: DeserializeOwned + Send + Sync> OutputSchema<T> for StructuredOutputSchema<T>
impl<T: DeserializeOwned + Send + Sync> OutputSchema<T> for StructuredOutputSchema<T>
Source§fn mode(&self) -> OutputMode
fn mode(&self) -> OutputMode
The preferred output mode for this schema.
Source§fn tool_definitions(&self) -> Vec<ToolDefinition>
fn tool_definitions(&self) -> Vec<ToolDefinition>
Get tool definitions if using tool mode. Read more
Source§fn json_schema(&self) -> Option<ObjectJsonSchema>
fn json_schema(&self) -> Option<ObjectJsonSchema>
Get JSON schema for native/prompted mode. Read more
Source§fn parse_text(&self, text: &str) -> Result<T, OutputParseError>
fn parse_text(&self, text: &str) -> Result<T, OutputParseError>
Parse output from text.
Source§fn parse_tool_call(
&self,
name: &str,
args: &JsonValue,
) -> Result<T, OutputParseError>
fn parse_tool_call( &self, name: &str, args: &JsonValue, ) -> Result<T, OutputParseError>
Parse output from a tool call.
Source§fn parse_native(&self, value: &JsonValue) -> Result<T, OutputParseError>
fn parse_native(&self, value: &JsonValue) -> Result<T, OutputParseError>
Parse output from native structured response.
Source§fn supports_mode(&self, mode: OutputMode) -> bool
fn supports_mode(&self, mode: OutputMode) -> bool
Whether this schema supports a given output mode.
Auto Trait Implementations§
impl<T> Freeze for StructuredOutputSchema<T>
impl<T> RefUnwindSafe for StructuredOutputSchema<T>where
T: RefUnwindSafe,
impl<T> Send for StructuredOutputSchema<T>where
T: Send,
impl<T> Sync for StructuredOutputSchema<T>where
T: Sync,
impl<T> Unpin for StructuredOutputSchema<T>where
T: Unpin,
impl<T> UnwindSafe for StructuredOutputSchema<T>where
T: UnwindSafe,
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