Skip to content

AI Integration and Prompting

` framing from the content if present 1.

diagram

Prompts are constructed in src/ppt_craft/prompts.py using a modular approach to ensure byte-stability for prefix caching 2. The system prompt is built by concatenating four sections: §A (Design Reference), §B (JSON Schema), §C (Few-Shot Examples), and §D (Standing Instructions).

§A provides OOXML and PowerPoint design rules, such as font sizes, bullet point limits, and layout choices. §B defines the strict JSON schemas for Storyline (Phase A), Single Slide (Phase B), and Critique outputs. §C includes byte-stable few-shot examples for storyline and single-slide generation. §D enforces stylistic rules, including British spelling, tone, and constraints on consultantese.

User prompts are generated dynamically based on the phase. build_storyline_user_prompt accepts intent, theme, audience, and optional slide count to guide Phase A. build_slide_user_prompt incorporates prior titles to avoid repetition and provides the specific storyline entry for Phase B. Repair and critique prompts are built using build_repair_user_prompt and build_critique_user_prompt, which inject validation errors or existing JSON into the user message.

The system requires AI outputs to be enclosed in a ```json fenced block. The extract_json function in prompts.py uses a regular expression (_FENCE_RE) to locate the first JSON fence in the model’s response.

If a match is found, the function returns the content inside the fence, stripped of whitespace. If no fence is detected, it returns the raw text stripped of leading/trailing whitespace. This extracted string is then passed to standard JSON parsers for validation and consumption by the renderer.