Jump to content

Connect SuperML | Leeroopedia MCP: Equip your AI agents with best practices, code verification, and debugging knowledge. Powered by Leeroo — building Organizational Superintelligence. Contact us at founders@leeroo.com.

Implementation:Predibase Lorax Validation Schema Extraction

From Leeroopedia


Knowledge Sources
Domains Structured_Output, Validation
Last Updated 2026-02-08 02:00 GMT

Overview

Concrete tool for extracting and threading JSON schema constraints through the request validation pipeline provided by Validation::validate() in the Rust router.

Description

The Validation::validate() method in router/src/validation.rs processes incoming generate requests. At lines 353-358, it extracts the response_format schema, serializes it to a JSON string, and sets it on NextTokenChooserParameters.schema. If no schema is provided but the type is JsonObject, the default_json_schema() function provides a permissive JSON object schema.

Usage

Used internally during request validation. Not called directly by users.

Code Reference

Source Location

  • Repository: LoRAX
  • File: router/src/validation.rs
  • Lines: 196-410 (validate method), 353-358 (schema extraction)
  • File: router/src/lib.rs
  • Lines: 525-553 (ResponseFormat, default_json_schema)

Signature

impl Validation {
    pub(crate) async fn validate(
        &self,
        request: GenerateRequest,
    ) -> Result<ValidGenerateRequest, ValidationError> {
        // ...
        // Lines 353-358: Schema extraction
        let schema = request.parameters.response_format
            .as_ref()
            .and_then(|rf| {
                rf.schema.as_ref().map(|s| serde_json::to_string(s).unwrap())
            });
        // schema is set on NextTokenChooserParameters
        // ...
    }
}

// Default schema for json_object without explicit schema
fn default_json_schema() -> serde_json::Value {
    // Returns a permissive JSON object schema
}

Import

use crate::validation::Validation;

I/O Contract

Inputs

Name Type Required Description
GenerateRequest struct Yes Request with optional response_format

Outputs

Name Type Description
ValidGenerateRequest struct Validated request with schema string in NextTokenChooserParameters

Usage Examples

How Schema Flows Through Validation

# Client sends:
# POST /generate
# {
#   "inputs": "Extract the name:",
#   "parameters": {
#     "response_format": {
#       "type": "json_object",
#       "schema": {"type": "object", "properties": {"name": {"type": "string"}}}
#     }
#   }
# }

# Server-side validation extracts:
# schema_str = '{"type":"object","properties":{"name":{"type":"string"}}}'
# This string is passed to NextTokenChooserParameters.schema
# Which reaches the OutlinesLogitsProcessor for FSM compilation

Related Pages

Implements Principle

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment