$git clone https://github.com/lfnovo/ai-prompterStop hardcoding prompts. Start building maintainable, reusable AI prompt templates.
| 1 | # AI Prompter: Professional Prompt Management Made Simple |
| 2 | |
| 3 | **Stop hardcoding prompts. Start building maintainable, reusable AI prompt templates.** |
| 4 | |
| 5 | AI Prompter is a powerful Python library that transforms how you manage AI prompts. Using familiar Jinja2 templating, you can create dynamic, reusable prompts that scale with your applications - whether you're building chatbots, content generators, or complex AI workflows. |
| 6 | |
| 7 | ## Why AI Prompter? |
| 8 | |
| 9 | - **🎯 Template-Driven**: Write prompts once, reuse everywhere with dynamic variables |
| 10 | - **📁 Organized**: Keep prompts in separate files, organized and version-controlled |
| 11 | - **🔧 Flexible**: Works with any LLM provider - OpenAI, Anthropic, local models |
| 12 | - **⚡ LangChain Ready**: Seamless integration with LangChain workflows |
| 13 | - **🏗️ Structured Output**: Built-in support for JSON, Pydantic models, and custom parsers |
| 14 | - **🎨 Modular**: Include and compose templates for complex prompt engineering |
| 15 | |
| 16 | ## Quick Start |
| 17 | |
| 18 | ### Installation |
| 19 | |
| 20 | ```bash |
| 21 | pip install ai-prompter |
| 22 | |
| 23 | # For LangChain integration |
| 24 | pip install ai-prompter[langchain] |
| 25 | ``` |
| 26 | |
| 27 | ### 30-Second Example |
| 28 | |
| 29 | ```python |
| 30 | from ai_prompter import Prompter |
| 31 | |
| 32 | # Create a simple prompt template |
| 33 | prompter = Prompter(template_text=""" |
| 34 | You are a {{ role }} expert. Help the user with their {{ task_type }} question. |
| 35 | |
| 36 | User Question: {{ question }} |
| 37 | |
| 38 | Please provide a {{ tone }} and detailed response. |
| 39 | """) |
| 40 | |
| 41 | # Use it with different scenarios |
| 42 | response = prompter.render({ |
| 43 | "role": "Python programming", |
| 44 | "task_type": "debugging", |
| 45 | "question": "Why is my list comprehension not working?", |
| 46 | "tone": "friendly" |
| 47 | }) |
| 48 | |
| 49 | print(response) |
| 50 | # Output: You are a Python programming expert. Help the user with their debugging question... |
| 51 | ``` |
| 52 | |
| 53 | ### File-Based Templates (Recommended) |
| 54 | |
| 55 | Create a `prompts/` folder in your project and save templates as `.jinja` files: |
| 56 | |
| 57 | ```jinja |
| 58 | <!-- prompts/code_review.jinja --> |
| 59 | You are an experienced {{ language }} developer conducting a code review. |
| 60 | |
| 61 | Code to review: |
| 62 | ```{{ language }} |
| 63 | {{ code }} |
| 64 | ``` |
| 65 | |
| 66 | Focus on: |
| 67 | {% for focus_area in focus_areas %} |
| 68 | - {{ focus_area }} |
| 69 | {% endfor %} |
| 70 | |
| 71 | Provide specific, actionable feedback with examples. |
| 72 | ``` |
| 73 | |
| 74 | ```python |
| 75 | from ai_prompter import Prompter |
| 76 | |
| 77 | # Load the template by name (finds prompts/code_review.jinja automatically) |
| 78 | reviewer = Prompter(prompt_template="code_review") |
| 79 | |
| 80 | prompt = reviewer.render({ |
| 81 | "language": "python", |
| 82 | "code": "def calculate(x, y): return x + y", |
| 83 | "focus_areas": ["error handling", "documentation", "performance"] |
| 84 | }) |
| 85 | ``` |
| 86 | |
| 87 | ## Features |
| 88 | |
| 89 | - Define prompts as Jinja templates. |
| 90 | - Load default templates from `src/ai_prompter/prompts`. |
| 91 | - Override templates via `PROMPTS_PATH` environment variable. |
| 92 | - Automatic project root detection for prompt templates. |
| 93 | - Render prompts with arbitrary data or Pydantic models. |
| 94 | - Export to LangChain `ChatPromptTemplate`. |
| 95 | - Automatic output parser integration for structured outputs. |
| 96 | |
| 97 | ## Installation & Setup |
| 98 | |
| 99 | ### Basic Installation |
| 100 | |
| 101 | ```bash |
| 102 | # Install from PyPI |
| 103 | pip install ai-prompter |
| 104 | |
| 105 | # Or using uv (recommended for Python projects) |
| 106 | uv add ai-prompter |
| 107 | ``` |
| 108 | |
| 109 | ### With LangChain Integration |
| 110 | |
| 111 | ```bash |
| 112 | pip install ai-prompter[langchain] |
| 113 | # or |
| 114 | uv add ai-prompter[langchain] |
| 115 | ``` |
| 116 | |
| 117 | ### Development Installation |
| 118 | |
| 119 | ```bash |
| 120 | git clone https://github.com/lfnovo/ai-prompter |
| 121 | cd ai-prompter |
| 122 | uv sync # installs with all dev dependencies |
| 123 | ``` |
| 124 | |
| 125 | ## Configuration |
| 126 | |
| 127 | Configure a custom template path by creating a `.env` file in the project root: |
| 128 | |
| 129 | ```dotenv |
| 130 | PROMPTS_PATH=path/to/custom/templates |
| 131 | ``` |
| 132 | |
| 133 | ## Usage |
| 134 | |
| 135 | ### Basic Usage |
| 136 | |
| 137 | ```python |
| 138 | from ai_prompter import Prompter |
| 139 | |
| 140 | # Initialize with a template name |
| 141 | prompter = Prompter('my_template') |
| 142 | |
| 143 | # Render a prompt with variables |
| 144 | prompt = prompter.render({'variable': 'value'}) |
| 145 | print(prompt) |
| 146 | ``` |
| 147 | |
| 148 | ### Custom Prompt Directory |
| 149 | |
| 150 | You can specify a custom directory for your prompt templates using the `prompt_dir` parameter: |
| 151 | |
| 152 | ```python |
| 153 | prompter = Prompter(template_text='Hello {{ name }}!', prompt_dir='/path/to/your/prompts') |
| 154 | ``` |
| 155 | |
| 156 | ### Using Environment Variable for Prompt Path |
| 157 | |
| 158 | Se |