pub trait TextModelExt: TextModel {
// Required methods
fn complete_json<'life0, 'life1, 'async_trait>(
&'life0 self,
prompt: Prompt,
schema: &'life1 Schema,
) -> Pin<Box<dyn Future<Output = Result<Value, TextModelError>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait;
fn complete_as<'life0, 'async_trait, T>(
&'life0 self,
prompt: Prompt,
) -> Pin<Box<dyn Future<Output = Result<T, TextModelError>> + Send + 'async_trait>>
where T: JsonSchema + DeserializeOwned + Send + 'async_trait,
Self: 'async_trait,
'life0: 'async_trait;
}Expand description
Structured output on any TextModel (issue #580). Blanket-implemented
for every TextModel, so an adapter cannot override — and cannot skip —
the schema check, the validation, or the repair retry; import the trait
to call the methods.
Required Methods§
Sourcefn complete_json<'life0, 'life1, 'async_trait>(
&'life0 self,
prompt: Prompt,
schema: &'life1 Schema,
) -> Pin<Box<dyn Future<Output = Result<Value, TextModelError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn complete_json<'life0, 'life1, 'async_trait>(
&'life0 self,
prompt: Prompt,
schema: &'life1 Schema,
) -> Pin<Box<dyn Future<Output = Result<Value, TextModelError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
Completes prompt and returns a value that conforms to schema.
The schema is checked on the supported subset before the first call,
the prompt’s Prompt::json_schema is set to it, and the answer —
native structured output, or text parsed as JSON — is validated
against it. On failure the model gets one repair retry; a second
failure is TextModelError::SchemaViolation.
§Errors
TextModelError::InvalidSchemaifschemauses a keyword the validator does not implement; the model is never called.TextModelError::SchemaViolationif the answer still does not conform after the repair retry. The message names the failed path and reason only, never the model’s output.- Whatever
completeitself returned, unchanged:NotConfigured,Rejected,Transient,Transport,Unsupported.
Sourcefn complete_as<'life0, 'async_trait, T>(
&'life0 self,
prompt: Prompt,
) -> Pin<Box<dyn Future<Output = Result<T, TextModelError>> + Send + 'async_trait>>where
T: JsonSchema + DeserializeOwned + Send + 'async_trait,
Self: 'async_trait,
'life0: 'async_trait,
fn complete_as<'life0, 'async_trait, T>(
&'life0 self,
prompt: Prompt,
) -> Pin<Box<dyn Future<Output = Result<T, TextModelError>> + Send + 'async_trait>>where
T: JsonSchema + DeserializeOwned + Send + 'async_trait,
Self: 'async_trait,
'life0: 'async_trait,
Completes prompt and deserializes the conforming value into T,
using T’s own schema (schema_for) as the constraint — the
typed form of TextModelExt::complete_json.
§Errors
The same as TextModelExt::complete_json, plus
TextModelError::SchemaViolation if the conforming value does not
deserialize into T (a shape the schema generator and the
deserializer disagree on).
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".