Structured Prompt Engineering for LLM Apps
Project description
⚙️ PromptKit
A production-grade library for structured LLM prompt engineering.
Explore the docs »
Report Bug
·
Request Feature
Why PromptKit?
Managing prompts for Large Language Models can quickly become messy. Hardcoding prompts as f-strings mixes logic with presentation, lacks validation, and makes reuse difficult.
PromptKit solves this by treating your prompts as structured, version-controlled assets. By defining prompts in YAML files, you get:
- Clean Separation: Prompt templates are separate from application code
- Safety & Reliability: Built-in validation ensures prompts receive correct inputs
- Reusability: Define a prompt once, use it anywhere
- Clarity: Human-readable format anyone can understand
Features
- 📝 Declarative: Define prompts in YAML with Jinja2 templating
- 🔍 Validation: Pydantic-based input validation before rendering
- 🏗️ Engine Abstraction: Supports OpenAI and Ollama
- 💰 Cost Estimation: Estimate token counts and costs before execution
- 🖥️ CLI: Render, run, lint, and inspect prompts from terminal
- 🧪 Typed: Full type hints for IDE support
Quick Start
Installation
pip install promptkit-core
Define a Prompt
Create greet.yaml:
name: greet
description: Generates a personalized greeting
template: |
Hello {{ name }}!
{% if context %}
Context: {{ context }}
{% endif %}
How can I help you today?
input_schema:
name: str
context: "str | None"
Use in Python
from promptkit import load_prompt, run_prompt, OpenAIEngine
prompt = load_prompt("greet.yaml")
engine = OpenAIEngine(api_key="sk-...")
response = run_prompt(prompt, {"name": "Alice"}, engine)
print(response)
Use the CLI
export OPENAI_API_KEY="sk-..."
# Run the prompt
promptkit run greet.yaml --name Alice
# Render template without calling AI
promptkit render greet.yaml --name Alice
# Validate prompt structure
promptkit lint greet.yaml
# Get prompt information
promptkit info greet.yaml
# Estimate costs
promptkit cost greet.yaml --model gpt-4 --name Alice
Prompt Structure
Every prompt YAML file contains:
name: Unique identifierdescription: Human-readable descriptiontemplate: Jinja2 template with variablesinput_schema: Type definitions for inputs
Input Schema Types
input_schema:
name: str # Required string
age: int # Required integer
score: float # Required float
active: bool # Required boolean
tags: list # Required list
data: dict # Required dictionary
email: "str | None" # Optional string
Engines
OpenAI
from promptkit import OpenAIEngine
engine = OpenAIEngine(
api_key="sk-...",
model="gpt-4o-mini",
temperature=0.7,
max_tokens=1000
)
Ollama (Local)
from promptkit.engines import OllamaEngine
engine = OllamaEngine(
model="llama2",
temperature=0.7
)
Documentation
See the documentation for detailed guides and API reference.
Contributing
Contributions welcome. See CONTRIBUTING.md for guidelines.
License
MIT License - see LICENSE for details.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file promptkit_core-0.1.1.tar.gz.
File metadata
- Download URL: promptkit_core-0.1.1.tar.gz
- Upload date:
- Size: 30.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
05e5e1483a3f5874cec6f79862d219711bdbc66d48b9560e17fe255c841fe319
|
|
| MD5 |
4c6f2700d3b7191bb9b2b7a81e02698f
|
|
| BLAKE2b-256 |
71332f63d90f0258d45ec98fbbc74496200845f0a6ee3cb29fb1669841eba4af
|
File details
Details for the file promptkit_core-0.1.1-py3-none-any.whl.
File metadata
- Download URL: promptkit_core-0.1.1-py3-none-any.whl
- Upload date:
- Size: 22.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c27477cff7bedfb8b5240eee8b0f22baee7efab3e4e4fbd5291fa34d5109070d
|
|
| MD5 |
44a9b9ab68eb2674a08a79be478f0d80
|
|
| BLAKE2b-256 |
173917a26d5f5847e564c2789c193ee9e7a648a419ee72c76bb0542b217dea3a
|