> ## Documentation Index
> Fetch the complete documentation index at: https://docs.joyfill.io/llms.txt
> Use this file to discover all available pages before exploring further.

# Schema Validation

This guide shows you how to validate document structure using Joyfill's schema validation system.

### **What is Schema Validation**

Schema validation checks if your JSON document follows the correct Joyfill document structure before creating a form.

### **Enabling/Disabling Schema Validation**

Schema validation is **enabled by default** in `rememberDocumentEditor`:

```kotlin theme={null}
// Disable schema validation
val editor = rememberDocumentEditor(
    json = jsonString,
    validateSchema = false // default is true
)
```

### **How It Works**

When `validateSchema = true`:

1. Document is validated against the Joyfill schema during editor creation
2. If validation fails, an error is set and the `onError` callback is triggered
3. If validation passes, the editor is created normally

### **Schema Error Types**

| Error Type                | Code                      | When It Happens                               | Example                                          |
| ------------------------- | ------------------------- | --------------------------------------------- | ------------------------------------------------ |
| **SchemaError.Assertion** | ERROR\_SCHEMA\_VALIDATION | Document structure doesn't match schema rules | Missing required properties like files or fields |
| **SchemaError.Format**    | ERROR\_SCHEMA\_FORMAT     | JSON format is invalid                        | Empty/blank string or malformed JSON             |
| **SchemaError.Version**   | ERROR\_SCHEMA\_VERSION    | Document version incompatible with SDK        | Document created with newer SDK version          |

### **Error Monitoring**

Monitor schema errors reactively:

```kotlin theme={null}
@Composable
fun FormWithSchemaValidation() {
    val editor = rememberDocumentEditor(json = jsonString)
    val error = editor.error.watchAsState()
    
    if (error != null) {
        // Schema validation failed
        Text("Schema Error: ${error.message}")
    } else {
        // Schema is valid, show form
        Form(editor = editor)
    }
}
```

## Things to know

Schema validation is enabled by default (`validateSchema = true`). Disabling schema validation can lead to crashes and should only be used for testing. Schema errors include both user-friendly messages and technical details. Validation happens during editor creation, not during form interaction.
