Enforce Schema
Synopsis
Validates log entries against predefined schemas and enforces data structure compliance using Avro or Parquet schema definitions.
Schema
- enforce_schema:
description: <text>
schema: <string>
schema_type: <string>
requirement_filter: <string>
disabled: <boolean>
if: <script>
ignore_failure: <boolean>
on_failure: <processor[]>
on_success: <processor[]>
tag: <string>
Configuration
The following fields are used to define the processor:
| Field | Required | Default | Description |
|---|---|---|---|
schema | Y | Schema reference or definition: a Library schema name, a built-in model name, an inline JSON definition, or a Kusto column list (see Details) | |
schema_type | N | "parquet" | Schema format type ("avro" or "parquet") |
requirement_filter | N | "all" | Filter for schema field requirements |
disabled | N | false | Disable the processor without removing it from the pipeline |
description | N | - | Explanatory notes |
if | N | - | Condition to run |
ignore_failure | N | false | See Handling Failures |
on_failure | N | - | See Handling Failures |
on_success | N | - | See Handling Success |
tag | N | - | Identifier |
Details
The processor validates log entries against schema definitions to ensure data structure compliance. It supports two schema formats:
- Avro schemas: JSON-based schema definitions that provide rich data type validation and evolution support
- Parquet schemas: Column-oriented schema definitions optimized for analytics and big data processing
The schema value is resolved by name first, then as a definition: a Library schema name managed in the Library, a built-in model name (such as ocsf or udm), an inline JSON definition, or a Kusto column list (field:type,...). Set schema_type to avro or parquet to select the format; it defaults to parquet. For Parquet, a named schema is also resolved from schema files in the user and package schemas/ directories. The JSON definition format is documented under Avro and Parquet.
For Parquet schemas, requirement_filter projects a subset of fields: all (the default) emits every field, while a comma-separated list of required, optional, and recommended emits only matching fields. This lets one schema serve both a required-only and a full projection. It has no effect on Avro schemas.
The processor caches compiled schemas using content hashing for performance optimization. When validation occurs, the log entry is automatically transformed to match the schema requirements, including:
- Type coercion: Converting compatible types to match schema expectations
- Field validation: Ensuring required fields are present
- Structure enforcement: Organizing nested data according to schema hierarchy
- Default value assignment: Adding missing fields with default values where defined
For schemas whose name starts with ocsf (case-insensitive), the unmapped field is automatically skipped during enforcement. For schemas whose name starts with udm, the additional field is skipped.
Schema enforcement is particularly useful in data pipelines where downstream systems require strict data contracts and consistent field types.
Schema validation can modify the original log entry structure. Fields that don't match the schema may be transformed, removed, or have their types changed to ensure compliance.
Use schema caching effectively by keeping schema definitions consistent. The processor uses content hashing to cache compiled schemas, so identical schema strings will reuse cached versions.
Examples
Library Schema Reference
Reference a schema registered in the Library by name... | |
fields are coerced to the types declared in the | |
Basic Parquet Schema
Enforce a Parquet schema defined in JSON... | |
string values are coerced to the declared numeric types: | |
Avro Schema Validation
Use an Avro schema for rich validation... | |
ensuring proper data types: | |
Nested Structure Validation
Validate complex nested structures... | |
with proper type enforcement: | |
Default Values
Schema with default values... | |
automatically adds missing fields: | |
Array Validation
Validate arrays with typed elements... | |
with automatic type conversion: | |
Union Types
Handle union types for flexible fields... | |
choosing the best matching type: | |
Error Handling
Handle validation errors gracefully... | |
by adding error information: | |
Conditional Schema Enforcement
Apply schemas conditionally... | |
based on event characteristics: | |