Exceptions

PAL defines a hierarchy of exceptions for error handling.

Base Exception

PALError

Specific Exceptions

PALValidationError

PALLoadError

PALCompilerError

PALExecutorError

PALResolverError

PALMissingVariableError

PALMissingComponentError

PALCircularDependencyError

Exception Handling Examples

Basic error handling:

from pal import PromptCompiler
from pal.exceptions import PALError, PALMissingVariableError

compiler = PromptCompiler()

try:
    prompt = compiler.compile_from_file_sync("my_prompt.pal")
except PALMissingVariableError as e:
    print(f"Missing variables: {e.context['missing_variables']}")
except PALError as e:
    print(f"PAL error: {e}")

Detailed error information:

from pal import Loader
from pal.exceptions import PALValidationError

loader = Loader()

try:
    assembly = loader.load_prompt_assembly("invalid.pal")
except PALValidationError as e:
    print(f"Validation failed: {e}")
    for error in e.context['validation_errors']:
        print(f"  - {error['loc']}: {error['msg']}")