babylon.engine.observers.schema_validator
JSON Schema validation for observer outputs (Sprint 3.2).
Provides schema validation for NarrativeFrame and other observer JSON outputs. Uses Draft 2020-12 JSON Schema with referencing registry for $ref resolution.
Usage:
from babylon.engine.observers.schema_validator import validate_narrative_frame
frame = {"pattern": "SHOCK_DOCTRINE", "causal_graph": {...}}
errors = validate_narrative_frame(frame)
if errors:
for error in errors:
print(f"Validation error: {error}")
Functions
|
Check if a NarrativeFrame is valid against the JSON schema. |
|
Iterate over validation errors for a NarrativeFrame. |
|
Validate a NarrativeFrame against the JSON schema. |
- babylon.engine.observers.schema_validator.validate_narrative_frame(frame)[source]
Validate a NarrativeFrame against the JSON schema.
- Parameters:
frame (
dict[str,Any]) – Dictionary representing the NarrativeFrame to validate.- Return type:
- Returns:
List of validation error messages. Empty list if valid.
Example
>>> frame = {"pattern": "TEST", "causal_graph": {"nodes": [], "edges": []}} >>> errors = validate_narrative_frame(frame) >>> # Returns errors because nodes must have minItems: 1
- babylon.engine.observers.schema_validator.is_valid_narrative_frame(frame)[source]
Check if a NarrativeFrame is valid against the JSON schema.
Convenience method that returns a boolean instead of error list.
- Parameters:
frame (
dict[str,Any]) – Dictionary representing the NarrativeFrame to validate.- Return type:
- Returns:
True if valid, False otherwise.
Example
>>> frame = { ... "pattern": "SHOCK_DOCTRINE", ... "causal_graph": { ... "nodes": [{"id": "n1", "type": "ECONOMIC_SHOCK", "tick": 0}], ... "edges": [] ... } ... } >>> is_valid_narrative_frame(frame) True