MCPcopy Create free account
hub / github.com/AI45Lab/Code / validate_against_schema

Function validate_against_schema

core/src/llm/structured.rs:594–604  ·  view source on GitHub ↗

Validate a JSON value against a JSON Schema. Returns Ok(()) on success, or a list of human-readable error strings.

(value: &Value, schema: &Value)

Source from the content-addressed store, hash-verified

592/// Validate a JSON value against a JSON Schema.
593/// Returns Ok(()) on success, or a list of human-readable error strings.
594fn validate_against_schema(value: &Value, schema: &Value) -> Result<(), Vec<String>> {
595 // We do a basic recursive validation here. For production, consider using
596 // the `jsonschema` crate, but to avoid adding a heavy dependency we implement
597 // the subset of JSON Schema that matters for structured output.
598 let errors = basic_schema_validate(value, schema, "");
599 if errors.is_empty() {
600 Ok(())
601 } else {
602 Err(errors)
603 }
604}
605
606/// Basic JSON Schema validator covering the most common constraints.
607fn basic_schema_validate(value: &Value, schema: &Value, path: &str) -> Vec<String> {

Calls 2

basic_schema_validateFunction · 0.85
is_emptyMethod · 0.45