Skip to main content

SchemaCleanr

Struct SchemaCleanr 

pub struct SchemaCleanr;
Expand description

JSON Schema cleaner optimized for LLM tool calling.

Implementations§

Source§

impl SchemaCleanr

Source

pub fn clean_for_gemini(schema: Value) -> Value

Clean schema for Gemini compatibility (strictest).

This is the most aggressive cleaning strategy, removing all keywords that Gemini’s API rejects.

Source

pub fn clean_for_anthropic(schema: Value) -> Value

Clean schema for Anthropic compatibility.

Source

pub fn clean_for_openai(schema: Value) -> Value

Clean schema for OpenAI compatibility (most permissive).

Source

pub fn clean_shared( schema: &Arc<Value>, strategy: CleaningStrategy, ) -> Arc<Value>

Zero-copy wrapper around Self::clean for Arc-shared tool schemas: returns the same Arc when the pre-scan proves cleaning is a no-op, deep-copying the tree only when a rewrite is actually needed.

Source

pub fn needs_cleaning(schema: &Value, strategy: CleaningStrategy) -> bool

Conservative read-only pre-scan: true when Self::clean with strategy could change schema.

False positives are allowed (a flagged schema may clean to an equal value); false negatives are not — !needs_cleaning(s) must imply clean(s) == s. The triggers mirror every rewrite path in clean_object: strategy-specific keyword removal, plus the strategy-independent rewrites ($ref resolution, constenum, anyOf/oneOf simplification and sibling-type skipping, and null-stripping in type arrays).

Source

pub fn clean(schema: Value, strategy: CleaningStrategy) -> Value

Clean schema with specified strategy.

Source

pub fn validate(schema: &Value) -> Result<()>

Validate that a schema is suitable for LLM tool calling.

Returns an error if the schema is invalid or missing required fields.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.