babylon.ai.persona_loader

Persona loader with JSON Schema validation (Sprint 4.2).

This module provides functions to load and validate persona JSON files against the persona.schema.json definition.

Follows the pattern established in schema_validator.py for the observer layer.

Usage:
>>> from babylon.ai.persona_loader import load_persona, load_default_persona
>>>
>>> # Load specific persona
>>> percy = load_persona(Path("path/to/persona.json"))
>>>
>>> # Load default persona (Percy Raskova)
>>> default = load_default_persona()

See also

babylon.ai.persona.Persona: The Pydantic model for personas. babylon.engine.observers.schema_validator: Pattern reference.

Functions

load_default_persona()

Load the default persona (Persephone 'Percy' Raskova).

load_persona(path)

Load and validate a persona from a JSON file.

Exceptions

PersonaLoadError(message, path[, errors])

Error raised when persona loading fails.

exception babylon.ai.persona_loader.PersonaLoadError(message, path, errors=None)[source]

Bases: Exception

Error raised when persona loading fails.

Parameters:
  • message (str)

  • path (Path)

  • errors (list[str] | None)

Return type:

None

path

Path to the persona file that failed to load.

errors

List of validation error messages (if validation failed).

__init__(message, path, errors=None)[source]

Initialize PersonaLoadError.

Parameters:
  • message (str) – Human-readable error message.

  • path (Path) – Path to the persona file.

  • errors (list[str] | None) – List of validation error messages.

Return type:

None

babylon.ai.persona_loader.load_persona(path)[source]

Load and validate a persona from a JSON file.

Parameters:

path (Path) – Path to the persona JSON file.

Return type:

Persona

Returns:

Validated Persona instance.

Raises:

PersonaLoadError – If file doesn’t exist, JSON is invalid, or schema validation fails.

Example

>>> from pathlib import Path
>>> from babylon.ai.persona_loader import load_persona
>>> persona = load_persona(Path("path/to/persona.json"))
>>> persona.name
"Persephone 'Percy' Raskova"
babylon.ai.persona_loader.load_default_persona()[source]

Load the default persona (Persephone ‘Percy’ Raskova).

Return type:

Persona

Returns:

The default Persona instance.

Raises:

PersonaLoadError – If the default persona file is missing or invalid.

Example

>>> from babylon.ai.persona_loader import load_default_persona
>>> percy = load_default_persona()
>>> percy.id
'persephone_raskova'