Loader API
The loader module provides unified file loading for all PAL file types.
Loader
Supported File Types
The loader supports three file types:
Prompt Assemblies (.pal) - Main prompt definitions
Component Libraries (.pal.lib) - Reusable components
Evaluation Suites (.eval.yaml) - Test configurations
Loading Methods
Each file type has both sync and async loading methods:
load_prompt_assembly()/load_prompt_assembly_async()load_component_library()/load_component_library_async()load_evaluation_suite()/load_evaluation_suite_async()
Examples
Basic file loading:
from pal import Loader
from pathlib import Path
loader = Loader()
# Load a prompt assembly
assembly = loader.load_prompt_assembly("my_prompt.pal")
# Load a component library
library = loader.load_component_library("components.pal.lib")
# Load evaluation suite
evaluation = loader.load_evaluation_suite("examples/evaluation/classify_intent.eval.yaml")
Async loading with context manager:
import asyncio
async def example():
async with Loader(timeout=60.0) as loader:
assembly = await loader.load_prompt_assembly_async("prompt.pal")
library = await loader.load_component_library_async(
"https://example.com/libs/personas.pal.lib"
)
asyncio.run(example())
Loading from URLs:
import asyncio
async def load_from_urls():
loader = Loader(timeout=30.0)
# Load from GitHub
library = await loader.load_component_library_async(
"https://raw.githubusercontent.com/org/repo/main/libs/tasks.pal.lib"
)
# Load from any HTTP source
assembly = await loader.load_prompt_assembly_async(
"https://example.com/prompts/analysis.pal"
)
asyncio.run(load_from_urls())
Error Handling
The loader raises specific exceptions:
PALLoadError- File cannot be loadedPALValidationError- File format is invalid
Example:
from pal import Loader
from pal.exceptions import PALLoadError, PALValidationError
loader = Loader()
try:
assembly = loader.load_prompt_assembly("invalid.pal")
except PALLoadError as e:
print(f"Failed to load file: {e}")
except PALValidationError as e:
print(f"Invalid format: {e}")
print(f"Validation errors: {e.context['validation_errors']}")