Technical Deep Dive

How Prompt Engineering works

A plain-English explanation of the prompt engineering system behind AI Prompt Builder — written for hiring managers, not just engineers.

Instead of typing raw questions into an AI, this app automatically builds structured prompts that assign expert roles, inject your personal context, and define exactly how the AI should respond.

Why raw prompts give mediocre answers

Most people type a question directly into ChatGPT or Gemini. The result is usually "pretty good" — but rarely expert-level.

❌ Typical raw prompt

What the user types
"How do I manage my AI project timeline?"
No context. No role assigned. No output format specified.
What AI returns
A generic 5-bullet answer that could apply to any project. No consideration of your team size, phase, or what format would actually be useful.

✓ What AI Prompt Builder generates

Role
You are a Senior PM who has shipped 10+ AI products at Google. You are sharp at early risk detection and move decisions forward in ambiguous situations.
Context
User: Manami, 42, AI Engineer/PM, Python, VS Code, intermediate level. Phase: Model development. Team: 3 engineers / 1 DS / 1 PM. Constraint: 6 months.
Request
How do I manage my AI project timeline? — Structure: Situation summary → Options A/B/C with pros/cons → Key risks.
Output Rules
Answer concisely. Don't make up information. Distinguish facts from opinions. Think step by step. Answer in Japanese.

3 engineering layers

Each layer solves a distinct problem that makes the final prompt dramatically more effective than a raw question.

🏗

Layer 1

Structured Prompt Assembly — templates.py

Every prompt is assembled from 4 mandatory sections: Role, Context, Request, and Output Rules. The build_prompt() function dynamically constructs a prompt guaranteed to have all four — regardless of category or language. This is prompt engineering as software engineering: repeatable, testable, and version-controlled.

1,700 lines of carefully crafted prompt logic
👤

Layer 2

Personal Profile Injection — storage.py

The app maintains a persistent user profile grouped by domain: common info, tech profile, recipe profile, study profile, and more. When a prompt is built, the relevant profile groups are automatically injected into the Context section — so the AI always knows who it's talking to.

Context-aware AI without repeating yourself every time
🔁

Layer 3

Multi-LLM Abstraction — gemini_client.py

The same prompt can be sent to Gemini or OpenAI with a single toggle. The abstraction layer handles provider selection, API key management, model selection, and error handling — all in one place. Switching models requires zero changes to the prompt logic.

Provider-agnostic LLM integration pattern

Every category assigns a different AI persona

Each category has a meticulously crafted expert persona with specific strengths and decision-making style.

🤖
AI-PM
Senior PM @ Google
Risk detection, ambiguity, business impact
💻
Code
Senior Engineer (15+ yrs)
Implementation + tests + security
📱
App Dev
Full-Stack AI/DS Engineer
Requirements to deployment
🧠
AI/ML Dev
Senior ML Researcher
Model design, data leakage, evaluation
💪
Health
Dietitian + Trainer
Evidence-based, personalized
📚
Study
Professor + Tutor
Intuitive → formal → practice
🌏
Language
Native + Language Coach
Natural corrections, your level
👨‍🍳
Recipe
Professional Chef
Your pantry, tools, dietary needs
💬
Chat
Conversation Partner
Practice with feedback
Other
Auto-assigned expert
AI self-declares its role

From click to AI response

What happens when a user submits a request — across Flask, the prompt engine, and the LLM API.

1

User fills in the form (Frontend → Flask)

The vanilla JS frontend sends a POST request to the Flask REST API. Flask has 20+ endpoints — each handling a specific concern: prompt building, AI calls, history, favorites, presets, profile.

# POST /api/build_prompt
{ "category": "ai_pm", "lang": "ja",
  "user_inputs": { "question": "..." },
  "include_profile": true }
2

Profile loaded and merged (storage.py)

get_profile_for_category() loads the relevant profile groups from JSON storage and returns them for injection into the prompt context.

# Category to profile mapping
CATEGORY_PROFILE_MAP = {
  "ai_pm": ["common", "tech"],
  "recipe": ["common", "recipe"],
}
3

Prompt assembled (templates.py → build_prompt)

build_prompt() constructs a multi-section prompt: Role → Context → Instructions → Request → Output Rules. Each section is populated from template definitions, user inputs, and profile data.

# Assembled sections
parts = [
  "[Role]" + role_text,
  "[Context]" + profile_text,
  "[Request]" + request_text,
  "[Output Rules]" + rules,
]
4

Sent to LLM (gemini_client.py)

ask_ai() reads the provider setting, retrieves the API key, and sends the completed prompt. The abstraction layer means the prompt engine works identically regardless of which LLM is selected.

# Provider abstraction
def ask_ai(prompt, client_settings=None):
  provider = settings.get("provider", "gemini")
  if provider == "openai":
    return ask_openai(prompt, ...)
  return ask_gemini(prompt, ...)

How this translates to your business

This systematic approach to prompt engineering transforms generative AI from an unpredictable toy into a reliable enterprise tool.

🎯

Output Quality Standardization

Ensure every employee, regardless of their AI skill level, extracts expert-level, consistently formatted output from LLMs.

🧠

Domain-Specific AI Assistants

Automatically inject internal company guidelines, brand voice, or customer context into every query without manual typing.

💸

API Cost & Time Optimization

Reduce the "trial and error" back-and-forth chatting. Get the exact output needed in a single API call, saving both tokens and employee time.

What this demonstrates

🎨

Prompt Engineering as a System

Most people treat prompts as one-off text. This project treats prompt construction as software: modular, testable, version-controlled, and reusable across 10 domains.

🔧

Full-Stack Python

Flask REST API + vanilla JS + JSON persistence + Docker + Gunicorn. Every layer is hand-built without heavy frameworks — demonstrating core engineering fundamentals.

🔁

Production LLM Patterns

Provider abstraction, environment variable key management, client-side override, and graceful error handling — the same patterns used in production AI systems.

🧭

Personal Tool, Real Product Thinking

Built for daily personal use — UX decisions were driven by real friction, not imagined requirements. Presets, favorites, history, and profile persistence all exist because they were genuinely needed.

See the code

The app is live. About 2 minutes to get your first result.