Files
maritime-logistics/src/llm/schema.rs
T

17 lines
544 B
Rust

//! Turns a Rust type into the JSON Schema object Anthropic expects as a
//! tool's `input_schema`.
use schemars::{schema_for, JsonSchema};
use serde_json::Value;
pub fn schema_value<T: JsonSchema>() -> Value {
let mut value = schema_for!(T).as_value().clone();
if let Some(object) = value.as_object_mut() {
// Anthropic's tool schema validator doesn't need (and can be
// confused by) the JSON-Schema-dialect metadata schemars adds.
object.remove("$schema");
object.remove("title");
}
value
}