Skip to main content

Module schema

Module schema 

Source
Expand description

A tool’s parameters derived from its arguments type, so the schema the model sees and the type its arguments are parsed into cannot disagree:

use schemars::JsonSchema;
use serde::Deserialize;

#[derive(Deserialize, JsonSchema)]
struct Args {
    /// How many lines to read.
    limit: Option<u32>,
}

let schema = rig_core::tool::args_schema::<Args>();
let limit = serde_json::json!({"type": "integer", "minimum": 0,
    "description": "How many lines to read."});
assert_eq!(schema["properties"]["limit"], limit);
assert_eq!(schema["additionalProperties"], false);

Functions§

args_schema
The JSON schema of the arguments type A, in the plain shape tool definitions use: inline, without $schema, title, default, format (providers support it unevenly) or the type’s own doc comment, and with Option fields optional, not nullable (no null type, enum value or anyOf alternative), and each object refusing keys it does not declare (additionalProperties: false, as deny_unknown_fields says; a map keeps its own).