Skip to main content

Module schema_utils

Module schema_utils 

Source
Expand description

Core traits and types.

Always available regardless of feature flags. Includes:

  • Agent - The fundamental trait for all agents
  • Tool / Toolset - For extending agents with capabilities
  • Session / State - For managing conversation context
  • Event - For streaming agent responses
  • AdkError / Result - Unified error handling JSON Schema utility functions.

§Schema Utilities

Shared utility functions for normalizing JSON Schema documents across multiple LLM provider adapters. Each function operates on serde_json::Value via mutable references for in-place transformation and recurses into nested schemas (properties, items, additionalProperties, allOf, anyOf, oneOf, etc.).

These utilities are independently unit-testable and composable — each adapter selects which transforms to apply and in what order.

§Example

use serde_json::json;
use adk_core::schema_utils;

let mut schema = json!({
    "$schema": "http://json-schema.org/draft-07/schema#",
    "type": "object",
    "properties": {
        "name": { "type": "string" }
    }
});

schema_utils::strip_schema_keyword(&mut schema);
assert!(schema.get("$schema").is_none());

Functions§

add_implicit_object_type
Adds "type": "object" when properties exists without a type field.
collapse_combiners
Collapses anyOf/oneOf arrays to the first non-null sub-schema.
collapse_type_arrays
Collapses type arrays to the first non-null type string.
convert_const_to_enum
Converts const values to single-element enum arrays.
enforce_nesting_depth
Enforces a maximum nesting depth for object schemas.
merge_all_of
Merges allOf arrays by combining all sub-schemas into a single schema.
resolve_refs
Resolves $ref references by inlining the referenced sub-schema from a definitions map.
strip_conditional_keywords
Removes conditional keywords (if, then, else) from the schema and all nested sub-schemas.
strip_null_from_enum
Removes JSON null values from enum arrays in the schema and all nested sub-schemas.
strip_schema_keyword
Removes the $schema keyword from the schema and all nested sub-schemas.
strip_unsupported_formats
Removes format values not in the allowed list from the schema and all nested sub-schemas.
truncate_tool_name
Truncates a tool name to at most max_bytes bytes, preserving valid UTF-8.