zerda.prompt — RAG Prompt Orchestration Engine

On this page

zerda.prompt is a Python library for building AI-ready, context-aware prompts for Retrieval-Augmented Generation (RAG) systems. It sits between your retriever and your LLM client, turning a query plus a bag of retrieved documents into a fully-assembled, guardrailed, token-budgeted, provider-ready prompt.

Python · 22 lines
from zerda.prompt import PromptEngine

engine = PromptEngine()

prompt = engine.build(
    query="What caused the 2008 financial crisis?",
    documents=[
        {"content": "...", "source": "wiki", "score": 0.92},
    ],
    strategy="multi_hop",
    output_format="json",
)

# OpenAI
response = openai_client.chat.completions.create(
    model="gpt-4o",
    messages=prompt.to_messages(),
)

# Anthropic
payload = prompt.to_anthropic()
response = anthropic_client.messages.create(**payload, model="claude-opus-4-20250514")

Scope note. This documentation describes only what is present in the prompt package source (__init__, prompt_engine, builder, context_manager, guardrails, optimizer, types, templates, strategies/__init__, ab_testing.py). No CLI, REST API, database layer, or plugin system exists in this package — the library is a pure in-process prompt-construction toolkit. Anywhere behavior can't be determined from the code, this is stated explicitly rather than guessed.

What it does

ConcernModuleSummary
Orchestrationprompt_enginePublic entry point (PromptEngine.build()); auto-detection, caching, metrics, feedback loop, hooks
Strategy dispatchbuilderResolves the effective strategy and wires context + guardrails into the strategy layer
Context engineeringcontext_managerDedup, "lost-in-the-middle" reordering, token-budget enforcement, citation mapping
Safety & instructionsguardrailsComposable, priority-ordered instruction injection (anti-hallucination, citations, PII, format)
Token reductionoptimizerWhitespace/filler stripping, cross-block dedup, hard token cap
Prompt shapesstrategies7 strategy implementations: Simple, CoT, Multi-Hop, Self-Consistent, Step-Back, ReAct, Least-to-Most
Bilingual scaffoldingtemplatesNatively-authored English/Arabic system personas, section labels, and guardrail text
Data contractstypesAll enums and dataclasses shared across the package
Offline evaluationab_testingCompare prompt variants with an LLM-as-judge harness

Where to go next