Building Gemini Conversion Workflows
Minimal pattern for any Gemini conversion workflow: prompt template + grounding data + system instructions + output schema.
Pythonimport google.generativeai as genai import os genai.configure(api_key=os.environ["GEMINI_API_KEY"]) model = genai.GenerativeModel( model_name="gemini-1.5-pro", system_instruction=( "You are a direct-response copywriter for {brand}. " "Voice: {tone}. Always output valid JSON matching the schema." ), ) prompt = f""" CONTEXT (grounding data): {customer_history_json} TASK: Write a 3-step abandoned cart recovery email sequence for this customer. Use chain-of-thought reasoning on their likely objection, then output final copy. OUTPUT SCHEMA: {{"emails": [{{"subject": "", "body": "", "send_delay_hours": 0}}]}} """ response = model.generate_content(prompt)
Every workflow in the repo follows this shape: Input data → Prompt (with CoT + few-shot + system instruction) → Structured output → Action (send/deploy/log) → Metric tracked.
Building a full conversion-workflow repo (50 workflows across 16 categories) follows this sequence:
Progress:
- [ ] 1. Set up repo skeleton and environment (API keys, folder structure)
- [ ] 2. Build core prompt system (templates, CoT, few-shot, system instructions)
- [ ] 3. Wire context/memory integration (CRM, long context, real-time grounding)
- [ ] 4. Implement workflows category-by-category (capture → qualify → convert → retain)
- [ ] 5. Instrument analytics/testing on every workflow
- [ ] 6. Document, version control, and add CI
- [ ] 7. Deploy, monitor, and scale
1. Repo & Environment
- Clone/init repo with folders:
/prompts,/workflows,/data,/tests,/docs,/config - Store secrets in
.env, never hardcode keys; load viaos.environ - Verify setup with a smoke test: one call to Gemini, print response
2. Prompt System
- Templates: parameterized strings with
{brand},{tone},{customer_data}slots - Chain-of-thought: instruct model to reason about buyer psychology/objection before writing final copy — separate reasoning from output using a schema or
---FINAL---delimiter - Few-shot: include 2-3 high-converting example outputs in-prompt to anchor style
- System instructions: lock brand voice, compliance constraints, and output format at the model level, not per-call
3. Context & Memory
- Pull CRM data (purchase history, engagement score, last touchpoint) into a JSON blob passed as grounding context
- Use long-context window for full customer history on high-value workflows (sales closing, VSL scripts); use compressed summaries for high-volume workflows (cart recovery, SMS)
- Ground time-sensitive prompts (pricing, inventory, live offers) with real-time data fetched right before the call — never cache pricing data in the prompt template
4. Workflow Implementation (by funnel stage)
Implement in this order, since later stages depend on data shapes from earlier ones:
- Capture: lead magnets, quizzes, forms, voice-to-lead, social comment import
- Qualify/Schedule: chatbot qualifier, lead scoring, appointment setting, call transcription
- Landing/Offer: dynamic copy, ad-to-page match, heatmap fixes, exit-intent, VSL scripts
- Checkout: cart recovery, one-click checkout, dynamic pricing, upsells, social proof
- Nurture: email sequences, SMS/WhatsApp, webinar funnels, case studies, demo personalization
- Closing: objection handling, proposals, contract sentiment, chat handover, voice closer
- Personalization: content recommender, real-time site personalization, SEO bridge, localization
- Community/Partnership: engagement-to-sale, influencer adaptation, affiliate/referral optimization
- Retention: loyalty nurture, churn prediction, renewal/upsell, win-back, LTV maximization
- Analytics: A/B test generation, dashboards, drop-off diagnosis, journey mapping, behavioral triggers
Each workflow = one file: input_schema → prompt → Gemini call → output_schema → action_hook → metric_logged.
5. Documentation & Version Control
- README per workflow category: purpose, inputs, outputs, example call
- Git: feature branch per workflow, PR with before/after conversion metric if available
- CI: lint prompts (no unresolved
{placeholders}), run schema validation tests on sample outputs
6. Deployment & Scaling
- One-click deploy config (Cloud Run/Vercel/similar) with env-based secrets
- Monitor: conversion rate per workflow, Gemini error rate, latency, token cost
- Scale: batch low-priority workflows (nurture emails), keep real-time workflows (chat, checkout) on low-latency paths
- Security: PII redaction before sending to model, data retention policy, compliance flags per region
Example 1: Abandoned Cart Recovery
Input: {customer: "Jane", cart_items: ["Yoga Mat"], abandoned_hours_ago: 2, past_purchases: 3}
Output:
JSON{"emails": [ {"subject": "Jane, your mat is waiting 🧘", "body": "...", "send_delay_hours": 1}, {"subject": "10% off if you complete today", "body": "...", "send_delay_hours": 24}, {"subject": "Last chance — cart expires soon", "body": "...", "send_delay_hours": 72} ]}
Example 2: Predictive Lead Scoring
Input: {email_opens: 5, pricing_page_visits: 3, demo_requested: false, company_size: "50-200"}
Output: {"score": 78, "tier": "hot", "next_action": "trigger AI appointment setter workflow"}
- Always separate reasoning (CoT) from final output so downstream systems parse cleanly
- Put brand voice/compliance rules in system instructions, not repeated in every prompt
- Ground with live data, never bake pricing/inventory/offers into static templates
- Log a conversion metric for every workflow from day one — retrofitting analytics is expensive
- Use few-shot examples pulled from your actual top-performing copy, not generic samples
- Keep high-volume workflows (SMS, cart recovery) cheap: shorter context, smaller model, cached prompts
- Keep high-stakes workflows (closing, VSL, proposals) rich: long context, full CoT, human review gate
- Don't hardcode API keys or commit
.envfiles - Don't skip the output schema — free-text Gemini output breaks automation pipelines
- Don't cache real-time grounding data (prices, stock, live offers) — always fetch fresh
- Don't reuse one system instruction across unrelated brands/workflows — voice drift causes conversion drops
- Don't deploy sales-closing or high-ticket voice AI workflows without a human escalation path
- Don't skip PII redaction before sending customer data to the model — compliance risk
- Don't treat all 50 workflows as equal priority — build capture → qualify → close first; retention/analytics layers depend on that data existing