Schema Management

Advanced schema management capabilities for defining, validating, and maintaining data schemas in ViewAI.

Overview

ViewAI provides comprehensive schema management tools that help you:

  • Automatically generate schemas from data

  • Define custom validation rules

  • Compare and migrate schemas

  • Export schemas in multiple formats

  • Ensure data consistency across your ML pipeline

Understanding Schemas

A schema in ViewAI defines the structure, types, and constraints of your model's input features. It includes:

  • Field Definitions: Data types, ranges, and categories for each feature

  • Validation Rules: Constraints for data quality and consistency

  • Metadata: Model information, creation timestamps, and statistics

Schema Structure

{
    "model_id": "my_model",
    "fields": {
        "age": {
            "type": "int",
            "min": 0,
            "max": 120
        },
        "income": {
            "type": "float",
            "min": 0.0,
            "max": 1000000.0,
            "mean": 55000.0,
            "std": 25000.0,
            "missing_count": 0
        },
        "region": {
            "type": "category",
            "choices": ["north", "south", "east", "west"],
            "allow_new_categories": False,
            "n_unique": 4,
            "missing_count": 0
        }
    },
    "metadata": {
        "created_at": "2025-10-11T12:00:00",
        "n_features": 3,
        "n_samples": 10000,
        "model_type": "RandomForestClassifier"
    }
}

Automatic Schema Generation

Basic Schema Generation

Generate schemas automatically from your training data:

Controlling Category Handling

Control how categorical features handle new values:

Custom Schema Definition

Defining Schemas Manually

Create schemas from scratch for precise control:

Updating Schema Fields

Modify individual schema fields after creation:

Schema Validation

Using SchemaValidator

Validate schema structure and data compliance:

Validating Data Against Schema

Ensure your data conforms to the schema:

Non-Strict Validation

Use non-strict mode for warnings instead of errors:

Schema Comparison

Comparing Schemas

Compare two schemas to identify differences:

Detecting Breaking Changes

Identify changes that could break existing integrations:

Generating Migration Plans

Create migration steps for schema updates:

Schema Export and Import

Exporting Schemas

Export to JSON

Export to Markdown Documentation

The generated Markdown includes:

  • Model ID and metadata

  • Field definitions with types and constraints

  • Categorical choices and numeric ranges

  • Creation timestamps and statistics

Importing Schemas

Schema Versioning

Version Control Best Practices

API Integration

Uploading Schemas to ViewAI

Fetching Schemas from ViewAI

Saving Schemas Locally

ModelSchemaManager Reference

Initialization

Core Methods

Handling Missing Values

Configuring Missing Value Rules

Complete Example

1

Prepare Data

2

Train Model

3

Generate Schema

4

Validate Schema

5

Validate Data

6

Export Schema

7

Upload to API

8

Modify Schema

9

Save New Version

10

Compare Versions

Best Practices

  • Version Control: Always version your schemas and track changes

  • Validation: Validate both schema structure and data before deployment

  • Documentation: Export schemas to Markdown for team documentation

  • Breaking Changes: Check for breaking changes before schema updates

  • Backup: Keep backup copies of production schemas

  • Testing: Test schema changes with sample data before production

  • Migration: Create and follow migration plans for schema updates

  • Consistency: Ensure schemas match between training and inference

  • Metadata: Include comprehensive metadata for debugging

  • Review: Review auto-generated schemas before deployment

Troubleshooting

Schema Upload Fails
Data Validation Errors
Type Mismatch
Missing Fields

Next Steps

  • Learn about Health Monitoring

  • Explore Model Registry

  • Review Best Practices

Was this helpful?