This project implements a prompt-engineering analysis and transformation system that treats prompt construction as a learnable software engineering skill, rather than trial-and-error interaction with LLMs.
It operationalizes a Prompt Composition Framework, computes a Prompt Quality Score (PQS), and empirically compares naïve prompts vs structured prompts using a deterministic transformation pipeline.
Large Language Models (LLMs) are widely used for tasks such as code generation, reasoning, and problem solving. However, the quality of the output is highly dependent on the quality of the input prompt.
Novice users typically write:
- vague prompts
- incomplete task descriptions
- missing constraints and validation criteria
This project addresses that gap by:
- formally defining prompt components,
- detecting which components a naïve prompt satisfies,
- transforming the prompt into a fully structured version,
- and quantifying prompt quality using a reproducible metric.
Each prompt is analyzed against six locked components:
| Component | Description |
|---|---|
| C1 | Task specification |
| C2 | Input / output specification |
| C3 | Constraints & efficiency requirements |
| C4 | Algorithmic & implementation guidance |
| C5 | Edge-case & boundary handling |
| C6 | Verification & validation instruction |
Prompt Quality Score measures prompt completeness, not output quality.
Definition:
PQS = (Number of present components) / 6
- Range:
0.0 – 1.0 - Naïve prompts typically score < 0.5
- Structured prompts always score
1.0by construction
Naïve Prompt
↓
Component Detection (C1–C6)
↓
Naïve PQS Computation
↓
Deterministic Prompt Transformation
↓
Structured Prompt (C1–C6 enforced)
↓
Structured PQS = 1.0
↓
LLM Execution
- Python
- Gemini API (google-genai)
- Deterministic PQS computation
- Robust JSON extraction and repair
-
Streamlit
-
Interactive visualization of:
- component qualification
- naïve vs structured PQS
- structured prompt
- final model output
Structured_Prompt_Generation/
│
├── app.py # Streamlit frontend
├── prompt_engine.py # Core prompt analysis & transformation engine
├── README.md # Project documentation
├── .env # API keys (not committed)
├── .gitignore
└── venv/ # Python virtual environment
python -m venv venv
source venv/bin/activate # Linux / macOS
venv\Scripts\activate # Windowspip install streamlit python-dotenv google-genaiCreate a .env file in the project root:
GEMINI_API_KEY=your_api_key_here
Add .env to .gitignore.
streamlit run app.pyOpen the browser at:
http://localhost:8501
-
Enter a naïve prompt (student-like, informal, incomplete).
-
Click “Refine and Execute”.
-
The system displays:
- which prompt components (C1–C6) are satisfied,
- naïve prompt PQS,
- the fully structured prompt,
- structured PQS (1.0),
- the final model-generated answer.
- No dataset dependency
- No fine-tuning
- Model treated as a black box
- JSON output sanitized and repaired before parsing
- PQS computed deterministically (model output is not trusted for scoring)
This implementation supports:
- empirical comparison of naïve vs structured prompts,
- reproducible prompt transformations,
- correlation studies between prompt quality and model performance.
It is suitable for:
- prompt-learning datasets,
- controlled experiments,
- research publications in AI-assisted software engineering.
- Currently single-prompt, single-run
- Python-only focus
- No batch evaluation UI (can be added)
- Batch evaluation for large datasets
- CSV export of PQS metrics
- Prompt complexity classification (Low / Medium / High)
- PQS vs correctness / efficiency correlation plots
- Multi-model comparison (Gemini Flash / Pro / Gemma)