Tutorial: Getting Started
On this page
This walks through building a small RAG prompt pipeline from scratch using zerda.prompt.
from zerda.prompt import PromptEngine, Document
2. Create an engine
engine = PromptEngine()
Defaults are production-ready: caching on, auto-detection on, a fresh ContextManager and GuardrailEngine underneath. See Configuration for every override.
3. Retrieve documents (external to this library)
zerda.prompt does not perform retrieval itself — it consumes whatever your retriever returns, in one of three shapes:
# As typed Document objects
docs = [Document(content="...", source="kb/article-1", score=0.91)]
# As plain dicts (looser keys accepted: content/text, source/url, score, metadata)
docs = [{"content": "...", "source": "kb/article-1", "score": 0.91}]
# As plain strings (source/score default)
docs = ["Refunds are processed within 14 business days."]
4. Build a prompt
prompt = engine.build(
query="How long do refunds take?",
documents=docs,
)
5. Send it to your LLM
messages = prompt.to_messages() # OpenAI-shaped
payload = prompt.to_anthropic() # Anthropic-shaped
6. Read back what the engine decided
print(prompt.strategy) # PromptStrategy.SIMPLE (default for QA)
print(prompt.guardrails_applied) # e.g. ['safe_output', 'concise', 'grounding', ...]
print(prompt.estimated_tokens)
Next: choose a strategy deliberately
By default, PromptEngine may auto-detect a strategy from your query (see _auto_detect). For predictable behavior in production, pass strategy= explicitly and consider enable_auto_detect=False at construction time:
engine = PromptEngine(enable_auto_detect=False)
prompt = engine.build(query="...", documents=docs, strategy="cot")