pub struct StructuredOutputTool { /* private fields */ }Expand description
Validates the model’s structured output against a JSON Schema (StructuredOutputTool).
A valid input is the result, as JSON content; an invalid one is an error result listing the
violations, so the model can retry. The schema’s top-level description is added to the tool
description.
Implementations§
Source§impl StructuredOutputTool
impl StructuredOutputTool
Sourcepub fn new(schema: JsonSchema) -> Result<Self>
pub fn new(schema: JsonSchema) -> Result<Self>
Sourcepub fn for_type<T: SchemarsJsonSchema>() -> Result<Self>
pub fn for_type<T: SchemarsJsonSchema>() -> Result<Self>
Creates the tool for the normalized schema of T.
§Errors
When the generated schema does not compile.
Sourcepub fn result_from_text(&self, message: &Message) -> Result<JsonValue>
pub fn result_from_text(&self, message: &Message) -> Result<JsonValue>
Validates the text of an assistant message as structured output, for providers that return it as JSON text instead of calling the tool. The text blocks, joined, must be exactly one JSON object.
§Errors
StructuredOutputError when the text is not a JSON object, or the object does not
validate (Structured output failed validation: ...).
Trait Implementations§
Source§impl Clone for StructuredOutputTool
impl Clone for StructuredOutputTool
Source§impl Debug for StructuredOutputTool
impl Debug for StructuredOutputTool
Source§impl Tool for StructuredOutputTool
impl Tool for StructuredOutputTool
Source§fn description(&self) -> &str
fn description(&self) -> &str
What the tool does; it must match the spec’s description.
Source§fn tool_spec(&self) -> ToolSpec
fn tool_spec(&self) -> ToolSpec
The spec sent to the model: name, description and input schema.
Source§fn stream(&self, context: ToolContext) -> ToolStream
fn stream(&self, context: ToolContext) -> ToolStream
Runs the tool. The stream is
'static, so the agent can run it on its own task.Auto Trait Implementations§
impl !RefUnwindSafe for StructuredOutputTool
impl !UnwindSafe for StructuredOutputTool
impl Freeze for StructuredOutputTool
impl Send for StructuredOutputTool
impl Sync for StructuredOutputTool
impl Unpin for StructuredOutputTool
impl UnsafeUnpin for StructuredOutputTool
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§impl<T> FutureExt for T
impl<T> FutureExt for T
§fn with_context(self, otel_cx: Context) -> WithContext<Self> ⓘ
fn with_context(self, otel_cx: Context) -> WithContext<Self> ⓘ
§fn with_current_context(self) -> WithContext<Self> ⓘ
fn with_current_context(self) -> WithContext<Self> ⓘ
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> 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 moreCreates a shared type from an unshared type.