Skip to main content

PAL - Prompt Assembly Language

Python License CI codecov

PAL (Prompt Assembly Language) is a framework for managing LLM prompts as versioned, composable software artifacts. It treats prompt engineering with the same rigor as software engineering, focusing on modularity, versioning, and testability.

See also the NodeJS version of PAL (WIP)

⚡ Features

  • Modular Components: Break prompts into reusable, versioned components
  • Template System: Powerful Jinja2-based templating with variable injection
  • Dependency Management: Import and compose components from local files or URLs
  • LLM Integration: Built-in support for OpenAI, Anthropic, and custom providers
  • Evaluation Framework: Comprehensive testing system for prompt validation
  • Rich CLI: Beautiful command-line interface with syntax highlighting
  • Flexible Extensions: Use .pal/.pal.lib or .yml/.lib.yml extensions
  • Type Safety: Full Pydantic v2 validation for all schemas
  • Observability: Structured logging and execution tracking

📦 Installation

# Install with uv (recommended)
uv add pal-framework

# Or with pip
pip install pal-framework

📁 Project Structure

my_pal_project/
├── prompts/
│   ├── classify_intent.pal     # or .yml for better IDE support
│   └── code_review.pal
├── libraries/
│   ├── behavioral_traits.pal.lib    # or .lib.yml
│   ├── reasoning_strategies.pal.lib
│   └── output_formats.pal.lib
└── evaluation/
    └── classify_intent.eval.yaml

🚀 Quick Start

1. Create a Component Library

For a detailed guide, read this.

# libraries/traits.pal.lib
pal_version: "1.0"
library_id: "com.example.traits"
version: "1.0.0"
description: "Behavioral traits for AI agents"
type: "trait"

components:
  - name: "helpful_assistant"
    description: "A helpful and polite assistant"
    content: |
      You are a helpful, harmless, and honest AI assistant. You provide
      accurate information while being respectful and considerate.

2. Create a Prompt Assembly

For a detailed guide, read this.

# prompts/classify_intent.pal
pal_version: "1.0"
id: "classify-user-intent"
version: "1.0.0"
description: "Classifies user queries into intent categories"

imports:
  traits: "./libraries/traits.pal.lib"

variables:
  - name: "user_query"
    type: "string"
    description: "The user's input query"
  - name: "available_intents"
    type: "list"
    description: "List of available intent categories"

composition:
  - "{{ traits.helpful_assistant }}"
  - |
    ## Task
    Classify this user query into one of the available intents:

    **Available Intents:**
    {% for intent in available_intents %}
    - {{ intent.name }}: {{ intent.description }}
    {% endfor %}

    **User Query:** {{ user_query }}

3. Use the CLI

# Compile a prompt
pal compile prompts/classify_intent.pal --vars '{"user_query": "Take me to google.com", "available_intents": [{"name": "navigate", "description": "Go to URL"}]}'

# Execute with an LLM
pal execute prompts/classify_intent.pal --model gpt-4 --provider openai --vars '{"user_query": "Take me to google.com", "available_intents": [{"name": "navigate", "description": "Go to URL"}]}'

# Validate PAL files
pal validate prompts/ --recursive

# Run evaluation tests
pal evaluate evaluation/classify_intent.eval.yaml

4. Use Programmatically

import asyncio
from pal import PromptCompiler, PromptExecutor, MockLLMClient

async def main():
    # Set up components
    compiler = PromptCompiler()
    llm_client = MockLLMClient("Mock response")
    executor = PromptExecutor(llm_client)

    # Compile prompt
    variables = {
        "user_query": "What's the weather?",
        "available_intents": [{"name": "search", "description": "Search for info"}]
    }

    compiled_prompt = await compiler.compile_from_file(
        "prompts/classify_intent.pal",
        variables
    )

    print("Compiled Prompt:", compiled_prompt)

asyncio.run(main())

🧪 Evaluation System

Create test suites to validate your prompts:

# evaluation/classify_intent.eval.yaml
pal_version: "1.0"
prompt_id: "classify-user-intent"
target_version: "1.0.0"

test_cases:
  - name: "navigation_test"
    variables:
      user_query: "Go to google.com"
      available_intents: [{ "name": "navigate", "description": "Visit URL" }]
    assertions:
      - type: "json_valid"
      - type: "contains"
        config:
          text: "navigate"

🏗️ Architecture

PAL follows modern software engineering principles:

  • Schema Validation: All files are validated against strict Pydantic schemas
  • Dependency Resolution: Automatic import resolution with circular dependency detection
  • Template Engine: Jinja2 for powerful variable interpolation and logic
  • Observability: Structured logging with execution metrics and cost tracking
  • Type Safety: Full type hints and runtime validation

🛠️ CLI Commands

Command Description
pal compile Compile a PAL file into a prompt string
pal execute Compile and execute a prompt with an LLM
pal validate Validate PAL files for syntax and semantic errors
pal evaluate Run evaluation tests against prompts
pal info Show detailed information about PAL files

🧩 Component Types

PAL supports different types of reusable components:

  • persona: AI personality and role definitions
  • task: Specific instructions or objectives
  • context: Background information and knowledge
  • rules: Constraints and guidelines
  • examples: Few-shot learning examples
  • output_schema: Output format specifications
  • reasoning: Thinking strategies and methodologies
  • trait: Behavioral characteristics
  • note: Documentation and comments

🤝 Contributing

We welcome contributions! Please see our Contributing Guide for details.

📄 License

This project is licensed under the MIT License - see the LICENSE file for details.

🆘 Support

🗺️ Roadmap

  • PAL Registry: Centralized repository for sharing components
  • Visual Builder: Drag-and-drop prompt composition interface
  • IDE Extensions: VS Code and other editor integrations

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pal_framework-0.1.0.tar.gz (201.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pal_framework-0.1.0-py3-none-any.whl (36.1 kB view details)

Uploaded Python 3

File details

Details for the file pal_framework-0.1.0.tar.gz.

File metadata

  • Download URL: pal_framework-0.1.0.tar.gz
  • Upload date:
  • Size: 201.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.12.5 {"installer":{"name":"uv","version":"0.12.5","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for pal_framework-0.1.0.tar.gz
Algorithm Hash digest
SHA256 1193095cb4538d5a66221b6bb97ad6018d72dbef238ba1f4d38c18972c2c6fa4
MD5 7c4afdfca67bc57fc26cab1237c063d7
BLAKE2b-256 b736ac16853d192e68a94a0c3050676db4faae4591cc0588cf74878265709742

See more details on using hashes here.

File details

Details for the file pal_framework-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: pal_framework-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 36.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.12.5 {"installer":{"name":"uv","version":"0.12.5","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for pal_framework-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 d5ae309556dc5ab7c3721924836aec7fed01f4699ad4826eb11fc77107fbdc0b
MD5 98fa61dd59705fa8884ca17a058c2bd7
BLAKE2b-256 997a762216170c30fb629e28e14028334d70a3e2203ddee7711aaba6d994e8e1

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page