Validator API Reference¶
Reference for schema validation functionality.
validate()¶
Validate a schema dictionary against the SlideGen schema specification.
Parameters:
schema(Dict[str, Any]): Schema dictionary to validate
Returns:
ValidationResult: Validation result object
Example:
from slidegen.validator import validate
schema = {
"presentation": {
"slides": [
{
"layout": "title",
"title": "Welcome"
}
]
}
}
result = validate(schema)
if result.is_valid:
print("Schema is valid!")
else:
for error in result.errors:
print(f"Error: {error.get('message')}")
ValidationResult¶
Result object returned by validate().
Properties¶
is_valid: bool¶
Whether the schema is valid.
errors: List[Dict[str, Any]]¶
List of validation errors. Each error is a dictionary with:
field(str): Field path where error occurredmessage(str): Error messagesuggestion(Optional[str]): Suggested fix
result = validate(schema)
for error in result.errors:
field = error.get("field", "unknown")
message = error.get("message", "unknown error")
suggestion = error.get("suggestion")
print(f"{field}: {message}")
if suggestion:
print(f" Suggestion: {suggestion}")
Error Format¶
Validation errors follow this structure:
{
"field": "slides[2].layout",
"message": "Invalid layout type 'invalid_layout'",
"suggestion": "Use one of: title, bullet_list, chart, table, ..."
}
Validation Rules¶
The validator checks:
- Schema Structure: Required fields, correct types
- Layout Types: Valid layout names
- Business Rules: Chart data format, bullet limits, etc.
- Data Sources: External file existence (if referenced)
CLI Validation¶
You can also validate from the command line:
Example: Comprehensive Validation¶
from slidegen.validator import validate
import json
def validate_schema(schema_path: str) -> bool:
"""Validate a schema file and print detailed errors."""
with open(schema_path, "r") as f:
if schema_path.endswith(".json"):
schema = json.load(f)
else:
import yaml
schema = yaml.safe_load(f)
result = validate(schema)
if result.is_valid:
print(f"✓ {schema_path} is valid")
return True
else:
print(f"✗ {schema_path} has {len(result.errors)} error(s):")
for i, error in enumerate(result.errors, 1):
field = error.get("field", "unknown")
message = error.get("message", "unknown error")
suggestion = error.get("suggestion")
print(f"\n {i}. {field}")
print(f" {message}")
if suggestion:
print(f" → {suggestion}")
return False
# Usage
validate_schema("deck.yaml")
See Also¶
- Core API - SlideGenerator validation integration
- User Guide: Schema Reference - Schema format documentation