An AI-powered developer tool that analyzes, critiques, and improves your prompts. Built with production-quality engineering practices: modular architecture, separation of concerns, and clean extensibility.
Give PromptForge any prompt and it returns:
- Intent — What the prompt is trying to achieve
- Issues — Problems with clarity, missing context, or structure
- Improved Prompt — A rewritten, optimized version
- Score — Quality rating from 1–10 with justification
- Before vs After — Side-by-side comparison of original and improved prompt
| Concept | How It's Used |
|---|---|
| System Prompt | Defines PromptForge's behavior as a prompt engineering expert |
| Few-Shot Prompting | Provides example critiques for consistent, high-quality output |
| Basic RAG | Injects prompt engineering best practices as context |
| Structured Output | Returns intent, issues, and improved prompt in a parseable format |
- Python — Core language
- OpenAI API — LLM backbone (GPT-4o-mini by default)
- Gradio — Web UI for interactive prompt optimization
prompt-critic-and-optimizer/
├── app.py # Entry point — launches the Gradio UI
├── requirements.txt # Python dependencies
├── .env.example # Environment variable template
├── .gitignore
│
├── config/
│ └── settings.py # Centralized configuration & env loading
│
├── prompts/
│ ├── system_prompt.py # System prompt defining AI behavior
│ └── few_shot.py # Few-shot examples for output consistency
│
├── rag/
│ └── knowledge_base.py # Prompt best practices injected as context
│
├── services/
│ ├── llm_service.py # OpenAI API wrapper
│ └── pipeline.py # Orchestration: analyze → critique → improve
│
└── utils/
└── parser.py # Output parsing & validation helpers
- Python 3.10+
- An OpenAI API key
-
Clone the repository
git clone https://github.com/hasnaat-iftikhar/prompt-critic-and-optimizer.git cd prompt-critic-and-optimizer -
Create a virtual environment (recommended)
python -m venv venv source venv/bin/activate # macOS/Linux venv\Scripts\activate # Windows
-
Install dependencies
pip install -r requirements.txt
-
Set up environment variables
cp .env.example .env
Open
.envand add your OpenAI API key:OPENAI_API_KEY=sk-your-actual-key-here OPENAI_MODEL=gpt-4o-mini
python app.pyThe app will start at http://127.0.0.1:7860 — open it in your browser.
All settings are managed through environment variables (loaded from .env):
| Variable | Default | Description |
|---|---|---|
OPENAI_API_KEY |
— | Your OpenAI API key (required) |
OPENAI_MODEL |
gpt-4o-mini |
Model to use for analysis |
MAX_TOKENS |
2048 |
Maximum tokens in LLM response |
TEMPERATURE |
0.7 |
Creativity level (0.0 = focused, 1.0 = creative) |
User Input (prompt)
│
▼
┌─────────────────┐
│ Gradio UI │ UI layer — input, results, before/after tabs
└────────┬────────┘
│
▼
┌─────────────────┐
│ Pipeline │ Orchestrates the full analysis flow
└────────┬────────┘
│
┌────┴─────────────────┐
│ │
▼ ▼
┌──────────┐ ┌─────────────────┐
│ Prompts │ │ RAG Knowledge │ Context & examples
│ (system │ │ Base (best │
│ + few- │ │ practices) │
│ shot) │ │ │
└────┬─────┘ └────────┬────────┘
│ │
└─────────┬─────────┘
│
▼
┌──────────────┐
│ LLM Service │ OpenAI API call
│ (OpenAI) │
└──────┬───────┘
│
▼
┌──────────────┐
│ Parser │ Extracts structured sections
└──────┬───────┘
│
▼
Structured Output
(Intent, Issues, Improved Prompt, Score)
This project is for educational and development purposes.