Skip to main content

StructuredOutput

Trait StructuredOutput 

Source
pub trait StructuredOutput: for<'de> Deserialize<'de> + JsonSchema {
    // Provided methods
    fn type_name() -> &'static str { ... }
    fn model_validate_json_value(value: &Value) -> Result<Self, Error> { ... }
    fn model_validate_json_str(value: &str) -> Result<Self, Error> { ... }
    fn get_structured_output_schema() -> Value { ... }
}
Expand description

A trait for structured output types that can be used with potatohead prompts agents and workflows.

§Example

use potatohead_macro::StructureOutput;
use serde::{Serialize, Deserialize};
use schemars::JsonSchema;

#[derive(Serialize, Deserialize, JsonSchema)]
struct MyOutput {
    message: String,
    value: i32,
}

impl StructuredOutput for MyOutput {}

let schema = MyOutput::get_structured_output_schema();

Provided Methods§

Source

fn type_name() -> &'static str

Source

fn model_validate_json_value(value: &Value) -> Result<Self, Error>

Validates and deserializes a JSON value into its struct type.

§Arguments
  • value - The JSON value to deserialize
§Returns
  • Result<Self, serde_json::Error> - The deserialized value or error
Source

fn model_validate_json_str(value: &str) -> Result<Self, Error>

Source

fn get_structured_output_schema() -> Value

Generates an OpenAI-compatible JSON schema.

§Returns
  • Value - The JSON schema wrapped in OpenAI’s format

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§