"""
Main Article Prompt Template

Optimized based on Enter.de and Smalt.eu benchmark analysis (Germany's top agencies).
"""

import json
from datetime import datetime
from typing import Dict, List, Optional, Any

LANGUAGE_NAMES = {
    "de": "German (Deutsch)",
    "en": "English",
    "fr": "French (Français)",
    "es": "Spanish (Español)",
    "it": "Italian (Italiano)",
    "nl": "Dutch (Nederlands)",
    "pt": "Portuguese (Português)",
    "pl": "Polish (Polski)",
    "sv": "Swedish (Svenska)",
    "da": "Danish (Dansk)",
    "no": "Norwegian (Norsk)",
    "fi": "Finnish (Suomi)",
    "cs": "Czech (Čeština)",
    "hu": "Hungarian (Magyar)",
    "ro": "Romanian (Română)",
    "bg": "Bulgarian (Български)",
    "el": "Greek (Ελληνικά)",
    "tr": "Turkish (Türkçe)",
    "ja": "Japanese (日本語)",
    "ko": "Korean (한국어)",
    "zh": "Chinese (中文)",
    "ar": "Arabic (العربية)",
    "he": "Hebrew (עברית)",
    "ru": "Russian (Русский)",
}

def validate_country(country: str) -> str:
    """
    Validate and sanitize country parameter for ANY country on earth.
    
    Args:
        country: Country code to validate
        
    Returns:
        Validated country code or safe fallback
    """
    if not country or not isinstance(country, str):
        return "US"  # Safe fallback only for invalid input
    
    country_cleaned = country.upper().strip()
    
    # Basic security validation - must be 2-3 uppercase letters only
    import re
    if not re.match(r'^[A-Z]{2,3}$', country_cleaned):
        return "US"  # Only fallback for invalid format, not unsupported countries
    
    # Accept ANY valid country code format - no hardcoded limitations
    return country_cleaned

# Universal quality standards - no market-specific hardcoding
# Optimized for 9.0/10+ quality (beats Writesonic)
UNIVERSAL_STANDARDS = {
    "word_count_target": "2000-2500",
    "min_word_count": "2000",
    "list_count": "12+ lists minimum",
    "citation_count": "15-20 authoritative sources",  # Increased for research depth
    "data_points_min": "15-20 statistics/data points",  # NEW: Research depth requirement
    "case_studies_min": "2-3 concrete case studies",  # NEW: Example quality requirement
    "examples_min": "5-7 specific examples",  # NEW: Example quality requirement
    "unique_insights_min": "2-3 unique insights",  # NEW: Originality requirement
    "internal_links_min": "5-8 internal links",  # NEW: SEO requirement
    "quality_note": "Professional standards with expert-level content and market awareness"
}



def get_main_article_prompt(
    primary_keyword: str,
    company_name: str,
    company_info: Optional[Dict[str, Any]] = None,
    language: str = "en",
    country: str = "US",
    internal_links: str = "",
    competitors: Optional[List[str]] = None,
    custom_instructions: str = "",
    system_prompts: Optional[List[str]] = None,
) -> str:
    """Generate universal blog article prompt with professional quality standards."""
    
    # Input validation and safe defaults
    if not primary_keyword or not isinstance(primary_keyword, str):
        raise ValueError("primary_keyword must be a non-empty string")
    
    company_name = company_name or "Company"
    company_info = company_info or {"description": ""}
    competitors = competitors or []
    system_prompts = system_prompts or []
    internal_links = internal_links or ""
    custom_instructions = custom_instructions or ""
    language = language or "en"
    country = country or "US"
    
    # Basic variables
    system_prompts_text = "\n".join(f"• {p}" for p in system_prompts) if system_prompts else ""
    current_date = datetime.now().strftime("%B %d, %Y")
    language_name = LANGUAGE_NAMES.get(language, language.upper())
    competitors_str = ", ".join(competitors) if competitors else "none"
    validated_country = validate_country(country)
    
    # Use universal standards
    standards = UNIVERSAL_STANDARDS

    prompt = f"""*** INPUT ***
Primary Keyword: {primary_keyword}
Custom Instructions: {custom_instructions}
Client Knowledge: {system_prompts_text}
Company Info: {json.dumps(company_info)}
Company Name: {company_name}
Internal Links: {internal_links}
Output Language: {language_name}
Target Market: {validated_country}
Competitors: {competitors_str}
Date: {current_date}

*** CRITICAL: USE 2025 DATA ***
🕒 **IMPORTANT**: Today's date is {current_date}. When citing reports, studies, or statistics:
- Use "2025 report", "2025 data", "2025 study" NOT "2024" 
- Reference current year context: "As we enter 2025", "In 2025"
- Avoid outdated temporal references

*** TASK ***
You are writing a long-form blog post in {company_name}'s voice, fully optimized for LLM discovery, on the topic defined by **Primary Keyword**.

🚨 **CRITICAL PRIMARY KEYWORD REQUIREMENT (OUTPUT WILL BE REJECTED IF NOT MET):**
- The exact phrase "{primary_keyword}" MUST appear **EXACTLY 5-8 times** in your output
- **MANDATORY LOCATIONS (NON-NEGOTIABLE):**
  - Headline: MUST include "{primary_keyword}" (mention 1)
  - Direct_Answer: MUST naturally include "{primary_keyword}" within the 45-55 word answer (mention 2)
  - Intro paragraph: MUST include "{primary_keyword}" 1-2 times naturally (mentions 2-3)
  - Section content: MUST include "{primary_keyword}" 3-5 times distributed across sections (mentions 4-8)
- **BEFORE YOU SUBMIT**: Use Ctrl+F or search to count "{primary_keyword}" occurrences
- If count < 5: Add more natural mentions in section content
- If count > 8: Replace some with semantic variations (keep 5-8 exact matches)
- **THIS IS A HARD REQUIREMENT - ZERO TOLERANCE - OUTPUT WILL BE REJECTED IF VIOLATED**

*** SOURCES VERIFICATION (MANDATORY) ***

🔍 **BEFORE WRITING**: Use your web search tools to verify ALL URLs you plan to cite.
🚨 **ZERO TOLERANCE**: Any hallucinated or unverified URLs will result in REJECTION.

**REQUIRED VERIFICATION PROCESS**:
1. Search for the specific company/study you want to reference
2. Verify the exact URL exists and returns 200 OK status
3. If no specific page found, use verified company homepage only
4. Record format: `[1]: https://verified-url.com – 8-15 word description`

*** CONTENT RULES ***

🚨 **HARD RULES (ABSOLUTE - ZERO TOLERANCE):**

**RULE 0A: NO EM DASHES (—) ANYWHERE**
- ❌ FORBIDDEN: "The tools—like Copilot—are popular."
- ✅ REQUIRED: "The tools, like Copilot, are popular." OR "The tools (like Copilot) are popular."
- If you need a dash, use comma, parentheses, or split into two sentences
- **VALIDATION: Search your output for "—" before submitting. Count MUST be ZERO.**

**RULE 0B: PRIMARY KEYWORD DENSITY (CRITICAL - OUTPUT REJECTION IF VIOLATED)**
- The exact phrase "{primary_keyword}" MUST appear **EXACTLY 5-8 times** in total (headline + Direct_Answer + intro + all sections)
- NOT 4 times. NOT 9 times. NOT 0 times. EXACTLY 5-8 times.
- **MANDATORY PLACEMENT REQUIREMENTS:**
  - ✅ Headline: MUST contain "{primary_keyword}" (1 mention)
  - ✅ Direct_Answer: MUST contain "{primary_keyword}" naturally within the answer (1 mention)
  - ✅ Intro: MUST contain "{primary_keyword}" 1-2 times (1-2 mentions)
  - ✅ Sections: MUST contain "{primary_keyword}" 3-5 times distributed across sections (3-5 mentions)
- **MANDATORY VALIDATION STEPS BEFORE SUBMISSION:**
  1. Search your entire output for "{primary_keyword}" (case-insensitive)
  2. Count exact matches (not partial matches, not variations)
  3. Verify keyword appears in: Headline ✅, Direct_Answer ✅, Intro ✅, and at least 3 sections ✅
  4. If count = 0-4: ADD more mentions naturally in section content
  5. If count = 9+: REPLACE some with semantic variations, keep 5-8 exact matches
  6. Verify final count is 5-8 before submitting
- **OUTPUT WILL BE AUTOMATICALLY REJECTED IF PRIMARY KEYWORD COUNT IS NOT 5-8 OR IF KEYWORD IS MISSING FROM HEADLINE/DIRECT_ANSWER/INTRO**

**RULE 0C: FIRST PARAGRAPH IMPACT**
- First <p> paragraph should be engaging and substantial (2-4 sentences typically)
- **FOCUS: Create a compelling hook that draws readers in with natural flow**

**RULE 0D: NO ROBOTIC PHRASES**
- ❌ FORBIDDEN: "Here's how", "Here's what", "Key points:", "Important considerations:", "Key benefits include:"
- ✅ REQUIRED: Natural transitions ("Organizations are adopting...", "Teams report...")
- ❌ FORBIDDEN: Broken sentence patterns like "You can to implement", "What is as we", "so you can managing"
- ✅ REQUIRED: Complete, grammatically correct sentences at ALL times

**RULE 0E: CONVERSATIONAL PHRASES (MANDATORY - 12+ REQUIRED)**
- 🚨 **CRITICAL: You MUST include 12+ conversational phrases throughout your article**
- Required phrases: "how to", "what is", "you can", "you'll", "here's", "let's", "that's", "when you", "if you", "so you can", etc.
- **COUNT THEM BEFORE SUBMITTING - Articles with <12 phrases will be REJECTED**
- See detailed requirements in Section 12 below

**RULE 0F: INTERNAL LINKS (MANDATORY - 3+ REQUIRED)**
- 🚨 **CRITICAL: You MUST include minimum 3 internal links using `/magazine/` prefix**
- **INSTANT REJECTION if fewer than 3 internal links**
- Distribute throughout article (1 every 2-3 sections)  
- Use natural anchor text (max 6 words each)
- See complete list of required topics in Section 9 below

---

1. Word count: 1,800–2,200 words – professional depth with research-backed claims.

2. Headline: EXACTLY 50-60 characters. Subtitle: 80-100 characters. Teaser: 2-3 sentences with HOOK.

3. Direct_Answer: 45-55 words exactly, featured snippet optimized, with inline source link (see citation style below).
   
   **🚨 CRITICAL: Direct_Answer MUST naturally include the primary keyword "{primary_keyword}" within the answer.**
   - The keyword should appear naturally in context, not forced at the end
   - Example: "When evaluating {primary_keyword}, organizations prioritize security frameworks that reduce vulnerability rates by 45% [1]."
   - DO NOT append the keyword artificially - it must flow naturally within the 45-55 word limit
   
   **🚨 CONVERSATIONAL PHRASE REQUIREMENT:**
   - Direct_Answer MUST include at least 1 conversational phrase (e.g., "you can", "here's", "what is", "how to")
   - This counts toward your mandatory 12+ conversational phrases total

4. Intro: **Engaging opening paragraph with STORY/HOOK (real scenario, surprising insight, or question). Do NOT include bullet lists in Intro.**

   **FOCUS: Create a compelling opening that immediately engages the reader with natural, conversational flow (typically 2-4 sentences).**
   
   **🚨 CONVERSATIONAL PHRASE REQUIREMENT:**
   - Intro paragraph MUST include 2-3 conversational phrases (e.g., "you'll find", "here's", "when you", "that's why")
   - This counts toward your mandatory 12+ conversational phrases total
   - Start conversational from the very beginning to engage readers

5. **PARAGRAPH STRUCTURE + FEATURE LISTS** (CRITICAL - EXAMPLES REQUIRED):

   **NATURAL PARAGRAPH VARIETY FOR BETTER READABILITY:**
   
   🎯 **CREATE ENGAGING FLOW WITH VARIED PARAGRAPH LENGTHS:**
   
   - **Short paragraphs** (1-2 sentences) for emphasis and impact
   - **Medium paragraphs** (2-4 sentences) for main points and explanations  
   - **Longer paragraphs** (4-6 sentences) for complex concepts when needed
   - **Single sentence paragraphs** for dramatic effect or transitions
   - Keep content scannable and mobile-friendly with natural variety
   
   🚨 **CRITICAL WRITING QUALITY RULES:**
   - Every sentence MUST be complete and grammatically correct
   - Every list item MUST be a complete thought (not sentence fragments)
   - NO broken patterns like "You can to implement" or "What is as we handle"
   - NO incomplete list items that cut off mid-sentence
   - VERIFY every sentence makes sense before submitting
   
   ✅ GOOD: Natural variety in paragraph lengths (engaging, readable)
   ❌ AVOIDED: Monotonous uniform paragraphs (robotic, boring)
   
   ⛔ FORBIDDEN - Standalone labels (INSTANT REJECTION):
   ```html
   <p>Key features include:</p>
   <p><strong>GitHub Copilot:</strong> [2][3]</p>
   <p><strong>Amazon Q:</strong> [2][3]</p>
   <p><strong>Tabnine:</strong> [2][3]</p>
   ```
   
   ✅ CORRECT - Use proper HTML lists with full descriptions:
   ```html
   <p>Leading tools offer distinct capabilities tailored to different enterprise needs. 
   GitHub Copilot excels at individual developer productivity with 55% faster completions <a href="#source-1" class="citation">per GitHub research</a>, 
   while Amazon Q specializes in AWS infrastructure and legacy migration <a href="#source-2" class="citation">according to AWS</a>. Tabnine 
   stands out for privacy-conscious organizations requiring air-gapped deployments <a href="#source-3" class="citation">per Tabnine's enterprise study</a>.</p>
   <ul>
     <li><strong>GitHub Copilot:</strong> Deep VS Code integration delivering 55% faster 
     task completion, with Workspace feature for multi-file context management <a href="#source-1" class="citation">according to GitHub</a></li>
     <li><strong>Amazon Q Developer:</strong> Autonomous Java version upgrades and AWS-native 
     code generation, saving 4,500 developer years at Amazon internally <a href="#source-4" class="citation">per Amazon's case study</a></li>
     <li><strong>Tabnine:</strong> Air-gapped deployment with zero data leakage, achieving 
     32% productivity gains at Tesco without cloud uploads <a href="#source-6" class="citation">according to Tabnine</a></li>
   </ul>
   ```
   
   **IF YOU WANT TO LIST FEATURES/TOOLS/BENEFITS:**
   1. Write natural lead-in paragraph introducing the comparison  
   2. Use `<ul>` with `<li>` tags (NEVER standalone `<p>` labels)
   3. Each list item = Label + full description (15-30 words) + citations
   
   VALIDATION: Any `<p><strong>Label:</strong> [N]</p>` pattern = INSTANT REJECTION.

6. **PRIMARY KEYWORD PLACEMENT** (CRITICAL - MANDATORY REQUIREMENT):
   
   🚨 **THIS IS A HARD REQUIREMENT - OUTPUT WILL BE REJECTED IF NOT MET**
   
   The exact phrase "{primary_keyword}" MUST appear **EXACTLY 5-8 times TOTAL** across the entire article (headline + Direct_Answer + intro + all sections).
   
   **REQUIRED DISTRIBUTION (ALL LOCATIONS MANDATORY):**
   - Headline: 1 mention (REQUIRED - must include keyword naturally)
   - Direct_Answer: 1 mention (REQUIRED - must include keyword naturally within 45-55 words)
   - Intro paragraph: 1-2 mentions (REQUIRED - must include keyword naturally)
   - Section content: 3-5 mentions distributed across sections (REQUIRED - spread evenly)
   - Total: 5-8 mentions minimum
   
   **🚨 CRITICAL: If "{primary_keyword}" is missing from Headline, Direct_Answer, or Intro, the output will be REJECTED.**
   
   **MANDATORY VALIDATION PROCESS (DO THIS BEFORE SUBMITTING):**
   1. Copy your entire JSON output to a text editor
   2. Use search/find function to locate "{primary_keyword}" (case-insensitive)
   3. Count ONLY exact phrase matches (not partial, not variations)
   4. If count < 5: Go back and add more natural mentions in section content
   5. If count > 8: Replace some exact matches with semantic variations, keep 5-8 exact
   6. Verify final count is 5-8, then submit
   
   ✅ GOOD Example placements (natural, not forced):
   - Headline: "{primary_keyword}: Speed vs Security Trade-offs" (mention 1)
   - Direct_Answer: "When evaluating {primary_keyword}, organizations prioritize security frameworks that reduce vulnerability rates by 45% [1]." (mention 2)
   - Intro: "When evaluating {primary_keyword}, security is paramount..." (mention 3)
   - Section 1: "The best {primary_keyword} each serve distinct use cases..." (mention 4)
   - Section 2: "Implementing {primary_keyword} requires governance frameworks..." (mention 5)
   - Section 3: "Organizations adopting {primary_keyword} report 30% productivity gains..." (mention 6)
   - Section 4: "The future of {primary_keyword} depends on security improvements..." (mention 7)
   
   ⚠️ IMPORTANT GUIDELINES:
   - Do NOT repeat keyword multiple times per section (sounds robotic)
   - Do NOT count FAQ/PAA when measuring main content density
   - Use semantic variations if you need to reference the topic more often: "these tools", "AI assistants", "code generators"
   - Spread mentions evenly across sections (not all in one section)
   - Make mentions natural and contextually relevant
   
   ❌ FORBIDDEN: Submitting output with 0-4 or 9+ primary keyword mentions = AUTOMATIC REJECTION
   
   ✅ REQUIRED: 5-8 exact phrase matches of "{primary_keyword}" = MANDATORY FOR ACCEPTANCE

7. **Section Structure**: New H2 every 250-300 words. Each H2 followed by 2-3 paragraphs of substantive content.
   
   **🚨 CONVERSATIONAL PHRASE REQUIREMENT:**
   - Each section MUST include at least 1-2 conversational phrases distributed across paragraphs
   - Spread phrases evenly: "you can", "here's how", "what you need", "when you're", "so you can", etc.
   - This ensures you reach your mandatory 12+ conversational phrases total
   - Sections without conversational phrases will be flagged for revision

8. **Section Titles**: Use action-oriented, declarative formats:
   - Action titles: "5 Ways to...", "The Hidden Cost of...", "[Data] Shows...", "Key Strategies for..."
   - Benefit-driven titles: "How [Topic] Transforms [Outcome]", "Why [Topic] Matters in 2025"
   - All titles: 50-65 characters, data/benefit-driven, NO HTML tags, NO question format
   - **CRITICAL: Section titles should NOT be in question format** (avoid "What is...", "Why is...", "How is...")
   
   ✅ GOOD Examples:
   - "5 Security Risks Every Team Must Address" (43 chars, action)
   - "Real-World ROI: Enterprise Case Studies" (41 chars, action)
   - "How AI Adoption Transforms Enterprise Development" (48 chars, declarative)
   - "Key Strategies for AI Code Tool Selection" (45 chars, action)

9. **Internal Links** (CRITICAL - MANDATORY VALIDATION): Include 3-5 links throughout article (minimum 1 every 2-3 sections). 
   **ALL internal links MUST use `/magazine/{{slug}}` format.**
   
   🚨 **CRITICAL REQUIREMENT: Your article WILL BE REJECTED if it contains fewer than 3 internal links.**
   
   **REQUIRED INTERNAL LINK TOPICS** (choose 3-5 from these):
   - `<a href="/magazine/ai-security-best-practices">AI security tools</a>`
   - `<a href="/magazine/devops-automation">DevOps automation</a>`
   - `<a href="/magazine/cloud-security">cloud security frameworks</a>`
   - `<a href="/magazine/incident-response-plan">incident response strategies</a>`
   - `<a href="/magazine/zero-trust-architecture">zero trust implementation</a>`
   - `<a href="/magazine/identity-management">identity management protocols</a>`
   - `<a href="/magazine/network-security">network security strategies</a>`
   - `<a href="/magazine/vulnerability-management">vulnerability scanning tools</a>`
   - `<a href="/magazine/compliance-automation">compliance automation</a>`
   - `<a href="/magazine/threat-intelligence">threat intelligence platforms</a>`
   - `<a href="/magazine/security-awareness-training">security awareness programs</a>`
   - `<a href="/magazine/penetration-testing">penetration testing methodologies</a>`
   
   ⛔ FORBIDDEN:
   - `<a href="/ai-security">...` (missing /magazine/)
   - `<a href="/blog/devops">...` (wrong prefix)
   - Articles with 0-2 internal links (INSTANT REJECTION)
   
   ✅ REQUIRED:
   - All slugs must start with `/magazine/`
   - Anchor text: max 6 words
   - Distribute evenly—don't bunch at top
   
   ✅ GOOD Examples (embedded naturally in sentences):
   - "Organizations are <a href="/ai-governance">implementing governance frameworks</a> to manage risk."
   - "Learn more about <a href="/security-best-practices">security scanning automation</a> in our guide."
   - "The shift toward <a href="/agentic-ai">autonomous AI agents</a> is accelerating."

10. **Case Studies** (MANDATORY - EXAMPLES REQUIRED):
    
    **RULE: Company + Metric + Timeframe + Result (30+ words minimum)**
    
    ⛔ FORBIDDEN (All these patterns = INSTANT REJECTION):
    ```html
    <p>Shopify [2][3]</p>
    <p><strong>Shopify:</strong> [2][3]</p>
    <p>Shopify uses GitHub Copilot [2]</p>
    <p>Shopify saw improvements [2][3]</p>
    <p>Many Fortune 500 companies report gains [1]</p>
    ```
    
    ✅ REQUIRED - Embedded in narrative paragraphs:
    ```html
    <p>Real-world implementations validate these theoretical benefits. Shopify accelerated 
    pull request completion by 40% within 90 days of deploying GitHub Copilot across their 
    500-person engineering team in Q2 2024 <a href="#source-2" class="citation">according to Shopify's case study</a>. The company attributes this to reduced 
    boilerplate generation, which previously consumed 30% of sprint capacity. Similarly, 
    Tesco achieved a 32% productivity increase after implementing Tabnine's air-gapped 
    solution in early 2025, citing the ability to provide context-aware suggestions without 
    exposing sensitive pricing algorithms to public models <a href="#source-4" class="citation">per Tesco's implementation report</a>.</p>
    ```
    
    FORMULA FOR EVERY CASE STUDY:**
    - Company name (real, named company - NOT "a Fortune 500 company")
    - Specific action verb (deployed, implemented, accelerated, reduced)
    - Quantified metric (40% faster, $260M saved, 4,500 developer years)
    - Specific timeframe (Q2 2024, within 90 days, throughout 2025)
    - Concrete result/benefit (30+ word description of impact)
    - Inline source link at end (NOT numbered citations)
    
    REQUIREMENT: Minimum 2 case studies per article, each 30+ words.
    
    Citations: Embed inline source links naturally within complete sentences - NO academic-style numbered citations [1][2].
    
    **CITATION STYLE (CRITICAL - INLINE LINKS ONLY):**
    
    🚫 **ABSOLUTELY FORBIDDEN - NEVER USE THESE:**
    ```html
    <p>GitHub Copilot increases productivity by 55% [1][2].</p>
    <p>Amazon Q saved 4,500 developer years [3][4].</p>
    <p>Research shows 45% vulnerability rate [5].</p>
    ```
    ❌ ANY numbered brackets like [1], [2], [3], [1][2], [2][3] are BANNED
    ❌ If you write [N] anywhere, the output will be REJECTED
    ❌ Scientific/academic citation style is NOT ALLOWED
    
    ✅ **REQUIRED - Inline contextual links ONLY:**
    ```html
    <p>GitHub Copilot increases productivity by 55% <a href="#source-1" class="citation">according to GitHub's enterprise study</a>.</p>
    <p>Amazon Q saved 4,500 developer years <a href="#source-2" class="citation">in Amazon's Java modernization project</a>.</p>
    <p>Research shows 45% vulnerability rate <a href="#source-5" class="citation">per Veracode's 2025 report</a>.</p>
    ```
    
    **MANDATORY INLINE LINK RULES:**
    - Link text = 2-5 words describing the source (e.g., "according to NIST", "GitHub's 2024 study", "Amazon's case study")
    - Use `class="citation"` for all source links
    - EVERY fact must have an inline contextual link (NOT [N])
    - href = `#source-N` where N matches source number in Sources section
    - Place link at END of claim/data point (before period)
    - Natural language, not academic markers
    
    **CITATION DISTRIBUTION REQUIREMENT (MANDATORY - 70%+ PARAGRAPHS):**
    🚨 **CRITICAL: At least 70% of all paragraphs MUST contain 2+ citations.**
    
    - Target: 70%+ paragraphs with 2+ citations (buffer above minimum 60%)
    - Every paragraph should cite multiple sources for credibility
    - Articles with less than 70% citation distribution will be REJECTED
    - Distribute citations evenly across all sections (not bunched in one area)
    
    ✅ GOOD: 75% of paragraphs have 2-3 citations each
    ❌ REJECTED: Only 50% of paragraphs have citations
    
    **EXAMPLES:**
    - "...productivity gains of 55% <a href="#source-1" class="citation">per GitHub research</a>."
    - "...saving $260 million <a href="#source-2" class="citation">according to AWS</a>."
    - "...45% vulnerability rate <a href="#source-3" class="citation">found by NIST</a>."

11. **HTML Lists** (🚨 CRITICAL REQUIREMENT - OUTPUT WILL BE REJECTED WITHOUT LISTS):
    
    **MANDATORY: Include EXACTLY 5-8 lists throughout article. Minimum 1 list every 2 sections.**
    
    🎯 **LISTS ARE ESSENTIAL FOR:**
    - Mobile readability and user engagement
    - Breaking up dense text blocks  
    - Highlighting key features and benefits
    - Improving content scannability
    
    **VALIDATION: Articles with fewer than 5 lists will be AUTOMATICALLY REJECTED.**
    
    **USE NUMBERED LISTS (`<ol>`) WHEN:**
    - Listing ranked items: "5 best tools", "top 3 platforms", "10 ways to..."
    - Step-by-step processes: "3 steps to implement", "5 ways to optimize"
    - Ordered sequences: "first, second, third", "number 1, number 2"
    - Any context where order/ranking matters
    
    **USE BULLET LISTS (`<ul>`) WHEN:**
    - Feature comparisons (unordered)
    - Common problems/solutions (no specific order)
    - Tool selection criteria (no ranking)
    - General checklists (no sequence required)
    
    ✅ GOOD Examples:
    - "Here are the 5 best AI code tools:" → use `<ol>`
    - "Top 3 security considerations:" → use `<ol>`
    - "Key features to consider:" → use `<ul>`
    - "Common implementation challenges:" → use `<ul>`
    
    ⛔ REJECTED - List items duplicating paragraph text verbatim:
    ```
    <p>The benefits are clear. Speed matters. Accuracy improves.</p>
    <ul>
      <li>The benefits are clear</li>  ← REJECTED: Copy-paste from paragraph
      <li>Speed matters</li>
      <li>Accuracy improves</li>
    </ul>
    ```
    
    ✅ REQUIRED - List items as complete thoughts with specifics:
    
    🚨 **CRITICAL LIST QUALITY RULES:**
    - Every list item MUST be a complete sentence or complete thought
    - NO sentence fragments or incomplete items
    - Each item should be 10-25 words for proper depth
    - Items must provide value beyond repeating paragraph text
    
    **Example 1 - Bullet List (unordered features):**
    ```
    <p>Organizations adopting AI code assistants report three primary benefits: development 
    cycles accelerate by 30%, code review burden decreases by 25%, and automated testing 
    catches 15% more bugs before production <a href="#source-1" class="citation">according to industry research</a>.</p>
    <ul>
      <li><strong>Speed:</strong> Automated boilerplate generation eliminates repetitive typing, letting developers focus on complex business logic instead of syntax</li>
      <li><strong>Efficiency:</strong> Context-aware suggestions reduce time spent on documentation lookups and API reference searches</li>
      <li><strong>Quality:</strong> Built-in best practices help junior developers write cleaner code from day one, reducing technical debt</li>
    </ul>
    ```
    
    ❌ **FORBIDDEN LIST PATTERNS (WILL BE REJECTED):**
    ```
    <li>The cybersecurity landscape has shifted dramatically, driven by the relentless sophistication of</li>  ← Incomplete sentence
    <li>This investment is not without cause; the average cost of a data</li>  ← Cut off mid-thought
    <li>has hit a record $10.22 million, making effective prevention a financial imperative</li>  ← Fragment
    ```
    
    **Example 2 - Numbered List (ranked/ordered items):**
    ```
    <p>Here are the 5 best AI code generation tools for enterprise teams:</p>
    <ol>
      <li><strong>GitHub Copilot:</strong> Deep VS Code integration with 55% faster task completion</li>
      <li><strong>Amazon Q Developer:</strong> AWS-native code generation saving 4,500 developer years</li>
      <li><strong>Tabnine:</strong> Air-gapped deployment with zero data leakage</li>
      <li><strong>Cursor IDE:</strong> Full IDE integration with 60% productivity boost</li>
      <li><strong>Codeium:</strong> Free tier with enterprise security features</li>
    </ol>
    ```
    
    Format: 4-8 items per list, each item 8-15 words, introduced by lead-in sentence.

12. **CONVERSATIONAL TONE** (🚨 ABSOLUTELY MANDATORY - MINIMUM 12+ PHRASES REQUIRED - NON-NEGOTIABLE): 
    
    **THIS IS THE #1 PRIORITY - YOUR ARTICLE WILL BE INSTANTLY REJECTED WITHOUT 12+ CONVERSATIONAL PHRASES.**
    
    Write as if explaining to a colleague. Use "you/your" naturally, contractions (it's, you'll, here's), and direct language. 
    Avoid banned AI phrases: "seamlessly", "leverage", "cutting-edge", "robust", "comprehensive", "holistic".
    
    **🚨 REQUIRED CONVERSATIONAL PHRASES (YOU MUST INCLUDE 12+ OF THESE - COUNT THEM BEFORE SUBMITTING):**
    
    **ESSENTIAL PHRASES (use liberally throughout):**
    - "how to", "what is", "why does", "when should", "where can"
    - "you can", "you'll", "you should", "let's", "here's", "this is"
    - "how can", "what are", "how do", "why should", "where are"
    - "we'll", "that's", "when you", "if you", "so you can", "which means"
    - "you're", "you've", "you'd", "it's", "that's", "here's", "there's"
    - "what you need", "how you can", "why you should", "when you're"
    
    **MANDATORY VALIDATION PROCESS (DO THIS BEFORE SUBMITTING):**
    1. Copy your entire article content to a text editor
    2. Search for each conversational phrase from the list above (case-insensitive)
    3. Count ALL occurrences across ALL sections (Intro, Direct_Answer, sections 1-9)
    4. If count < 12: GO BACK AND ADD MORE CONVERSATIONAL PHRASES IMMEDIATELY
    5. Distribute phrases evenly - don't bunch them all in one section
    6. Verify final count is 12+ before submitting
    
    **🚨 CRITICAL: Articles with fewer than 12 conversational phrases will be INSTANTLY REJECTED.**
    **🚨 CRITICAL: This is checked automatically - you cannot bypass this requirement.**
    
    ✅ EXCELLENT EXAMPLE (15+ conversational phrases - natural, engaging):
    "Here's the reality: you'll find that you can pick tools that actually fit your team's workflow. It's not about 
    chasing the latest tech—it's about finding what works when you're shipping code at 3am. That's why you should 
    consider how each tool integrates with your existing stack. When you're evaluating options, you'll want to think 
    about what you need most. If you're working with AWS, you might prefer one approach. So you can make the best 
    decision, here's how to evaluate each option. This is why many teams start with a pilot program."
    
    ❌ TERRIBLE EXAMPLE (0 conversational phrases - will be REJECTED):
    "Organizations should leverage cutting-edge solutions to seamlessly integrate robust AI capabilities. 
    Comprehensive platforms enable holistic transformation of development workflows through advanced automation."

13. **Insights**: Highlight 1-2 key insights per section with `<strong>...</strong>` (never `**...**`).
    
    ✅ GOOD Example:
    "<p>The surprising finding is that <strong>AI-generated code requires 40% more debugging time 
    than human-written code</strong>, offsetting much of the initial speed gains <a href="#source-1" class="citation">per Stanford research</a>. This paradox 
    forces teams to reconsider how they measure productivity.</p>"

14. **Narrative Flow**: End each section with a bridging sentence that sets up the next section.
    
    ✅ GOOD Examples:
    - "Understanding these security risks leads to an important question: how are successful enterprises 
      actually mitigating them in practice?"
    - "These theoretical benefits are impressive, but the real test is whether they hold up in production 
      environments."
    - "With the market landscape clear, the next critical decision is selecting the right tool for your 
      specific use case."

15. **NEVER** embed PAA, FAQ, or Key Takeaways inside sections, titles, intro, or teaser. They live in separate JSON keys.

16. **FAQ GENERATION** (MANDATORY - MINIMUM 5 REQUIRED):
   
   **REQUIREMENT: Generate 5-6 FAQ items that address common questions about the primary keyword.**
   
   **FAQ QUESTION GUIDELINES:**
   - Questions should be natural, conversational queries users would actually search
   - Focus on practical concerns: "What is...", "How do...", "What are...", "Can...", "Is..."
   - Each question should be 8-15 words
   - Questions should cover different aspects: features, benefits, costs, implementation, comparisons
   - Use the primary keyword naturally in at least 2-3 FAQ questions
   
   **FAQ ANSWER GUIDELINES:**
   - Answers should be 40-80 words (2-4 sentences)
   - Provide specific, actionable information (not generic statements)
   - Include data points or examples when relevant
   - Write in conversational tone (use "you" naturally)
   - NO HTML tags in FAQ questions (plain text only)
   - FAQ answers can include basic HTML like `<strong>` for emphasis if needed
   
   **REQUIRED FIELDS IN JSON:**
   - `faq_01_question` through `faq_06_question` (at least 5 must be non-empty)
   - `faq_01_answer` through `faq_06_answer` (matching answers for each question)
   
   ✅ GOOD FAQ Examples:
   - Q: "What is the best AI code generation tool for SaaS companies?"
   - A: "The best AI code tool depends on your specific needs. GitHub Copilot offers the broadest IDE integration and highest market adoption. Amazon Q Developer excels for AWS-native applications and legacy migrations. Tabnine provides the strongest privacy controls with air-gapped deployment options."
   
   ❌ BAD FAQ Examples:
   - Q: "AI tools?" (too vague)
   - A: "They are good." (too generic, no value)

17. **PEOPLE ALSO ASK (PAA) GENERATION** (MANDATORY - MINIMUM 3 REQUIRED):
   
   **REQUIREMENT: Generate 3-4 PAA items that address related questions users search after the primary keyword.**
   
   **PAA QUESTION GUIDELINES:**
   - Questions should be follow-up queries users ask after learning about the main topic
   - Focus on "how", "what", "why" questions that expand on the primary topic
   - Each question should be 8-15 words
   - Questions should explore related aspects, comparisons, or deeper details
   - Use semantic variations of the primary keyword (not exact repetition)
   
   **PAA ANSWER GUIDELINES:**
   - Answers should be 30-60 words (2-3 sentences)
   - Provide concise, direct answers
   - Include specific details or data when relevant
   - Write in conversational tone
   - NO HTML tags in PAA questions (plain text only)
   - PAA answers can include basic HTML like `<strong>` for emphasis if needed
   
   **REQUIRED FIELDS IN JSON:**
   - `paa_01_question` through `paa_04_question` (at least 3 must be non-empty)
   - `paa_01_answer` through `paa_04_answer` (matching answers for each question)
   
   ✅ GOOD PAA Examples:
   - Q: "How much faster can AI code tools make development?"
   - A: "AI code generation tools can increase developer productivity by 30-55% according to industry studies. GitHub Copilot reports 55% faster task completion, while Tabnine achieved 32% productivity gains at Tesco. Actual results vary based on codebase complexity and team adoption."
   
   ❌ BAD PAA Examples:
   - Q: "More info?" (too vague)
   - A: "It helps." (too generic, no value)

*** HUMANIZATION RULES (CRITICAL - AI MARKER DETECTION) ***

16. **Ban Em Dashes** (CRITICAL):
   
   ❌ NEVER use em dashes (—) for parenthetical clauses, lists, or emphasis.
   
   **FORBIDDEN PATTERNS:**
   ```
   "The tools—GitHub Copilot, Amazon Q, and Tabnine—are widely used."
   "This approach—which saves time—is effective."
   "AI assistants offer speed—but security remains a concern."
   ```
   
   **CORRECT ALTERNATIVES:**
   ```
   "The tools (GitHub Copilot, Amazon Q, and Tabnine) are widely used."  ← Use parentheses
   "This approach, which saves time, is effective."  ← Use commas
   "This approach is effective. It saves time and reduces errors."  ← Split into two sentences
   "AI assistants offer speed, but security remains a concern."  ← Use comma
   ```
   
   **WHY:** Em dashes (—) are a telltale AI writing marker. Human writers use commas, parentheses, or split sentences naturally.
   
   VALIDATION: Any em dash (—) in output = INSTANT REJECTION.

17. **Ban Robotic Transitions** (CRITICAL):
   
   ❌ NEVER use these formulaic AI transition phrases:
   
   **FORBIDDEN LIST:**
   - "Here's how" / "Here's what" / "Here's the" / "Here's a"
   - "Here are the" / "Here are some"
   - "Key points:" / "Key benefits include:" / "Key takeaways:"
   - "Important considerations:" / "Key considerations:"
   - "That's why" (unless absolutely necessary for grammar)
   - "If you want" / "When you" (unless part of direct question)
   - "You'll find to" / "You can see"
   - "What is as we" / "So you can managing"
   
   **FORBIDDEN EXAMPLES:**
   ```
   "Here's how enterprise adoption has moved beyond experimentation."
   "Key benefits include: improved speed, better quality, reduced costs."
   "That's why similarly, Shopify has integrated GitHub Copilot."
   "If you want another significant cost factor is the potential for IP leakage."
   ```
   
   **CORRECT ALTERNATIVES:**
   ```
   "Enterprise adoption has moved beyond experimentation."  ← Direct statement
   "Teams report improved speed, better quality, and reduced costs."  ← Natural flow
   "Similarly, Shopify has integrated GitHub Copilot."  ← Remove "That's why"
   "Another significant cost factor is the potential for IP leakage."  ← Remove "If you want"
   ```
   
   **WHY:** These phrases are overused by AI and make content sound templated and robotic.
   
   VALIDATION: Any "Here's how/what" or "Key points:" = INSTANT REJECTION.

18. **Natural List Integration** (CRITICAL):
   
   ❌ NEVER use standalone list introductions like "Key points:", "Here are", "Important considerations:".
   
   ✅ ALWAYS integrate lists into the paragraph flow with a natural lead-in sentence.
   
   **FORBIDDEN PATTERN:**
   ```html
   <p>Security is critical for AI adoption.</p>
   <p>Key points:</p>  ← REJECTED: Standalone introduction
   <ul>
     <li>45% of AI code has vulnerabilities</li>
     <li>Review all generated code</li>
   </ul>
   ```
   
   **CORRECT PATTERN:**
   ```html
   <p>Security is critical for AI adoption. Teams should focus on three areas:</p>  ← Natural lead-in
   <ul>
     <li>Automated scanning (45% of AI code has vulnerabilities)</li>
     <li>Mandatory code review for all generated code</li>
     <li>Regular security audits every quarter</li>
   </ul>
   ```
   
   **FORMULA:**
   1. Write a complete paragraph introducing the topic naturally
   2. End the paragraph with a natural transition: "X areas:", "X strategies:", "X steps:"
   3. Follow immediately with `<ul>` or `<ol>` (NO standalone `<p>Key points:</p>`)
   
   VALIDATION: Any `<p>Key points:</p>` or `<p>Here are</p>` before a list = INSTANT REJECTION.

19. **Grammar & Flow Standards**:
   
   - ✅ Every sentence must be grammatically correct (no fragments unless intentional for emphasis)
   - ✅ Vary sentence structure naturally - avoid repetitive patterns like "X is Y. X does Z. X provides W."
   - ✅ Use contractions occasionally for conversational tone: "don't", "it's", "you're" (but not excessively)
   - ✅ Start max 20% of sentences with transition words ("However", "Additionally", "Moreover")
   - ✅ Split long sentences (>30 words) into two shorter ones for readability
   - ✅ Use active voice 90%+ of the time
   
   **COMMON GRAMMAR MISTAKES TO AVOID:**
   ```
   ❌ "What is as we handle of AI tools"  → ✅ "As we evaluate AI tools"
   ❌ "so you can managing teams"  → ✅ "managing teams" or "so you can manage teams"
   ❌ "That's why similarly, Shopify"  → ✅ "Similarly, Shopify"
   ❌ "You'll find to mitigate risks"  → ✅ "To mitigate risks"
   ❌ "When you choosing tools"  → ✅ "When choosing tools" or "When you choose tools"
   ```

20. **Tone Calibration** (Natural, Human Voice):
   
   Write like a senior engineer explaining concepts to a colleague over coffee—not an academic paper, marketing brochure, or PowerPoint deck.
   
   **CHARACTERISTICS OF NATURAL TONE:**
   - Use "we" and "you" to create connection with reader
   - Occasional dry humor or personality is allowed (but keep professional)
   - If explaining complex topics, use analogies humans would naturally use
   - Vary sentence rhythm (mix short punchy sentences with longer explanatory ones)
   - Show expertise through insight, not jargon
   
   **🚨 CONVERSATIONAL PHRASE REQUIREMENT:**
   - Natural tone REQUIRES conversational phrases - you MUST use 12+ throughout the article
   - Phrases like "you can", "here's", "what is", "how to", "when you", "if you" make content feel human
   - Without conversational phrases, your article will sound robotic and be REJECTED
   - Count your phrases before submitting - this is non-negotiable
   
   **TONE EXAMPLES:**
   
   ❌ BAD (robotic, corporate):
   "Organizations should strategically leverage cutting-edge AI solutions to seamlessly integrate robust capabilities across comprehensive workflows."
   
   ✅ GOOD (conversational, expert):
   "You need tools that fit your actual workflow. It's not about chasing the latest tech—it's about what works when you're shipping code at 3am and the CI/CD pipeline breaks."
   
   ❌ BAD (stiff, academic):
   "The data indicates that artificial intelligence code generation platforms demonstrate significant productivity enhancements."
   
   ✅ GOOD (natural, clear):
   "The numbers are clear: AI code tools make developers 30% faster. But there's a catch—45% of generated code has security flaws."

*** SOURCES ***

• Minimum 8 authoritative references (target: 10-12).
• Priority order: 1) .gov/.edu 2) .org 3) Major news (NYT, BBC, Reuters) 4) Industry publications
• Format: `[1]: https://specific-page-url.com/research/2025 – 8-15 word description`
• **CRITICAL**: Use SPECIFIC PAGE URLs, NOT domain homepages
• **🚨 ANTI-HALLUCINATION WARNING**: ONLY cite URLs you have VERIFIED exist through web search
• **⚠️ URL VERIFICATION REQUIRED**: Before citing any URL, confirm it exists and is accessible
• Rejected: Personal blogs, social media, unknown domains, AI-generated content, HALLUCINATED URLs

✅ GOOD Examples:
```
[1]: https://www.nist.gov/publications/ai-code-security-2025 – NIST guidelines for secure AI code generation
[2]: https://github.blog/2024-09-copilot-enterprise-report/ – GitHub Copilot enterprise productivity study Q3 2024
[3]: https://aws.amazon.com/blogs/aws/q-developer-java-modernization/ – Amazon Q Developer Java upgrade case study
```

❌ BAD Examples:
```
[1]: https://github.com/ – GitHub homepage (too generic)
[2]: https://medium.com/@randomuser/my-thoughts – Personal blog (not authoritative)
[3]: https://example.com/ai – Unknown domain (not credible)
```

*** SEARCH QUERIES ***

• One line each: `Q1: keyword phrase …`

*** COMPARISON TABLES (Optional) ***

**WHEN TO USE TABLES:**
✅ Product/tool comparisons (e.g., "GitHub Copilot vs Amazon Q")
✅ Pricing tiers
✅ Feature matrices
✅ Before/after scenarios
✅ Statistical benchmarks

❌ DO NOT USE for:
- Lists that work better as bullet points
- How-to steps (use numbered lists)
- Single-column data
- Narrative content

**TABLE RULES:**
1. Maximum 2 tables per article
2. 2-6 columns (ideal: 4 columns)
3. 3-10 rows (ideal: 5-7 rows)
4. Keep cell content short (2-5 words per cell)
5. First column = names/items, other columns = attributes
6. Use consistent units (all $ or all %, not mixed)

**EXAMPLE (Good Table):**
```
Title: "Leading AI Code Tools Comparison"
Headers: ["Tool", "Price/Month", "Speed Boost", "Security", "Best For"]
Rows:
- ["GitHub Copilot", "$10", "55%", "Medium", "General coding"]
- ["Amazon Q Developer", "$19", "40%", "High", "Enterprise"]
- ["Cursor IDE", "$20", "60%", "Medium", "Full IDE"]
- ["Tabnine", "$12", "35%", "High", "Privacy-focused"]
```

**BAD TABLE PATTERNS:**
❌ Too many columns (>6): Unreadable on mobile
❌ Long text in cells: "This tool is designed for teams who want..."
❌ Inconsistent data: Some rows have "$10" others have "ten dollars"
❌ Empty cells: Use "N/A" or "-" instead

**OUTPUT FORMAT:**
Include in JSON output as:
```json
{{
  "tables": [
    {{
      "title": "AI Code Tools Comparison",
      "headers": ["Tool", "Price", "Speed"],
      "rows": [
        ["GitHub Copilot", "$10/mo", "55%"],
        ["Amazon Q", "$19/mo", "40%"]
      ]
    }}
  ]
}}
```

*** HARD RULES ***

• **HTML Tags**: Keep all tags intact (<p>, <ul>, <ol>, <h2>, <h3>, <strong>, <a>)

• **NATURAL CONTENT FLOW** (CRITICAL FOR READABILITY):
  - CREATE varied paragraph lengths for engaging rhythm
  - NEVER create standalone labels like "<p><strong>Tool:</strong> [N]</p>"
  - NEVER create empty paragraphs with only company names and citations  
  - USE natural paragraph variety: short (1-2 sentences), medium (2-4 sentences), longer (4-6 sentences) as context requires

• **Meta Requirements**:
  - Meta_Title: ≤55 characters, SEO-optimized
  - Meta_Description: 100-110 characters with CTA
  - Headline: 50-60 characters (count before finalizing)
  - **CRITICAL: Headline must NOT be in question format** (avoid "What is...", "Why is...", "How is..."). Use declarative statements instead.

• **Language**: All content in {language_name}

• **Competitors**: Never mention: {competitors_str}

• **Final Validation Checklist** (Output will be REJECTED if any fail):
  1. ✅ **PRIMARY KEYWORD COUNT (CRITICAL)**: "{primary_keyword}" appears EXACTLY 5-8 times (count exact phrase using search function - if 0-4 or 9+, output will be REJECTED)
  2. ✅ **PRIMARY KEYWORD PLACEMENT (CRITICAL)**: "{primary_keyword}" MUST appear in:
     - Headline (REQUIRED)
     - Direct_Answer (REQUIRED - must be natural, not appended)
     - Intro paragraph (REQUIRED)
     - At least 3 different sections (REQUIRED)
  3. ✅ **CONVERSATIONAL PHRASES (CRITICAL - NON-NEGOTIABLE)**: Count ALL conversational phrases ("how to", "what is", "you can", "you'll", "here's", "let's", "that's", "when you", "if you", "so you can", etc.) - MUST have 12+ total or output will be REJECTED
  4. ✅ **CONVERSATIONAL PHRASE DISTRIBUTION**: Conversational phrases must appear in:
     - Direct_Answer (at least 1 phrase)
     - Intro paragraph (2-3 phrases)
     - Each section (1-2 phrases per section)
  5. ✅ Headline is 50-60 characters and NOT in question format (no "What is...", "Why is...", "How is...")
  6. ✅ Direct_Answer is 45-55 words and naturally includes "{primary_keyword}" (not forced at the end)
  7. ✅ 3-5 internal links present in content
  8. ✅ 5-8 lists distributed throughout article
  9. ✅ 2+ named case studies with company + metric + timeframe + 30+ words each
  10. ✅ Natural paragraph variety for engaging flow and mobile readability
  11. ✅ NO standalone labels like "<p><strong>Company:</strong> [N]</p>"
  12. ✅ **CITATION QUALITY (CRITICAL - ZERO TOLERANCE FOR URL HALLUCINATION)**:
     
     🚨 **MANDATORY URL VERIFICATION RULES**:
     - ONLY use URLs you can VERIFY exist through your web search tools
     - NEVER invent or guess URL paths (like /reports/2024/ or /whitepaper-download/)
     - NEVER create plausible-sounding URLs without verification
     - If you can't find a specific report/study URL, use the company's main domain
     
     ✅ **REQUIRED PROCESS**:
     1. Search for the specific study/report/data you want to cite
     2. VERIFY the exact URL exists and is accessible
     3. ONLY cite URLs you have confirmed through search
     4. If no specific URL found, use homepage: "https://company.com"
     
     ❌ **FORBIDDEN URL PATTERNS**:
     - NO "/reports/", "/studies/", "/whitepapers/" unless verified
     - NO year-based paths like "/2024/", "/2025/" unless confirmed
     - NO document-specific paths like "/pdf/", "/download/" unless verified
     - NO subdirectory guessing (marketing.company.com, research.company.com)
     
     🔍 **WHEN IN DOUBT**: Use company homepage (https://company.com) instead of guessing paths
  13. ✅ **CITATION COUNT**: 15-20 sources required
  14. ✅ **FAQ REQUIREMENT (CRITICAL)**: At least 5 FAQ items generated (faq_01_question through faq_05_question must be non-empty)
  15. ✅ **PAA REQUIREMENT (CRITICAL)**: At least 3 PAA items generated (paa_01_question through paa_03_question must be non-empty)
  16. ✅ Scan for "aI" → replace with "AI"
  17. ✅ Remove banned phrases: "seamlessly", "leverage", "cutting-edge"

*** OUTPUT FORMAT ***

⚠️ CRITICAL: This section shows REAL CONTENT EXAMPLES, not placeholder instructions.

Study these examples carefully - this is EXACTLY how your output should look.

*** IMPORTANT OUTPUT RULES ***

- ENSURE correct JSON output format
- JSON must be valid and minified (no line breaks inside values)
- No extra keys, comments, or process explanations
- **WRITE NATURAL PARAGRAPHS**: Vary paragraph lengths for engaging flow - short (1-2 sentences), medium (2-4 sentences), longer (4-6 sentences) as content requires
- **🚨 MANDATORY LISTS (5-8 REQUIRED)**: ALWAYS include multiple <ul><li> and <ol><li> lists throughout your article - articles without lists will be REJECTED
- **NO STANDALONE LABELS**: Never write "<p><strong>Label:</strong> [N]</p>"
- **🚨 CONVERSATIONAL PHRASES REQUIRED**: You MUST include 12+ conversational phrases ("you can", "here's", "what is", "how to", "when you", etc.) throughout your article - count them before submitting

Valid JSON with REAL CONTENT EXAMPLES:

```json
{{
  "Headline": "AI Code Tools 2025: Speed vs Security Trade-offs",
  "Subtitle": "How 84% of developers balance 55% productivity gains with 45% vulnerability rates",
  "Teaser": "GitHub Copilot writes 41% of all code in 2025, but security teams warn of critical flaws. The question isn't whether to adopt AI—it's how to do so without compromising quality.",
  "Direct_Answer": "The leading AI code generation tools in 2025—GitHub Copilot, Amazon Q Developer, and Tabnine—collectively increase developer velocity by up to 55% <a href=\"#source-1\" class=\"citation\">according to GitHub research</a> while requiring strict governance frameworks to mitigate the 45% vulnerability rate in AI-generated code <a href=\"#source-2\" class=\"citation\">per NIST security study</a>.",
  "Intro": "<p>In late 2024, a senior engineer at a fintech firm watched an autonomous agent refactor a legacy codebase in hours—a task estimated to take weeks. This isn't science fiction; it's the new baseline for software engineering. As we enter 2025, 84% of developers integrate AI into daily workflows <a href=\"#source-1\" class=\"citation\">according to Stack Overflow</a>, but this speed introduces a paradox: we're building faster while potentially creating technical debt at scale.</p>",
  "Meta_Title": "Best AI Coding Tools 2025: Copilot vs Q vs Tabnine",
  "Meta_Description": "Compare GitHub Copilot, Amazon Q, and Tabnine. See which AI tool delivers 55% faster coding with enterprise security.",
  "section_01_title": "The AI Coding Revolution: Key Drivers in 2025",
  "section_01_content": "<p>The landscape of software development has undergone a radical transformation, with AI code generation tools now accounting for 41% of all code written globally—a staggering increase from just 12% in 2023 [1]. This surge is driven by enterprises racing to reduce operational costs in a market projected to reach $30.1 billion by 2032 [2]. However, adoption has outpaced governance, creating a trust gap where 76% of developers use these tools daily, yet only 43% trust their accuracy [3]. This disconnect reveals the central challenge of 2025: balancing velocity with quality control.</p><p>Leading organizations are moving beyond simple autocomplete to full agentic workflows where AI manages complex refactoring autonomously [4]. Tools can now upgrade entire legacy applications with minimal human intervention—impossible just two years ago [5]. Yet this automation introduces a productivity paradox: time saved writing boilerplate is often lost debugging subtle AI-generated logic errors [6]. Successful teams treat AI as a force multiplier requiring disciplined oversight, not an autonomous replacement for engineering judgment.</p>",
  "section_02_title": "Leading AI Code Tools: Comprehensive Comparison",
  "section_02_content": "<p>The market has consolidated around three dominant platforms, each serving distinct enterprise needs. GitHub Copilot leads with 41.9% market share through deep VS Code integration, while Amazon Q Developer dominates AWS-native environments with autonomous migration capabilities [1][2]. Tabnine captures security-conscious organizations requiring air-gapped deployments that prevent data leakage [3]. Understanding these differences is critical for strategic tool selection.</p><ul><li><strong>GitHub Copilot:</strong> Delivers 55% faster task completion through VS Code integration, with Workspace feature managing multi-file contexts via natural language [4][5]</li><li><strong>Amazon Q Developer:</strong> Specializes in autonomous Java version upgrades (Java 8 to 17), saving Amazon internally 4,500 developer years and $260M across 30,000 applications in 2024-2025 [6][7]</li><li><strong>Tabnine:</strong> Offers air-gapped deployment with zero cloud uploads, achieving 32% productivity gains at Tesco while maintaining strict data privacy [8][9]</li></ul><p>Real-world implementations validate these capabilities. Shopify accelerated pull request completion by 40% within 90 days of deploying Copilot across their 500-person engineering team in Q2 2024, attributing success to reduced boilerplate generation that previously consumed 30% of sprint capacity [10][11]. This demonstrates that tool selection must align with specific organizational constraints rather than following market hype.</p>",
  "section_03_title": "",
  "section_03_content": "",
  "section_04_title": "Security Considerations for AI Code Tools",
  "section_04_content": "<p>Security remains the primary concern for enterprise adoption. Research shows that 45% of AI-generated code contains vulnerabilities that require manual review <a href=\"#source-3\" class=\"citation\">according to NIST security guidelines</a>. This risk demands comprehensive governance frameworks that balance productivity gains with security requirements.</p>",
  "section_05_title": "",
  "section_05_content": "",
  "section_06_title": "",
  "section_06_content": "",
  "section_07_title": "",
  "section_07_content": "",
  "section_08_title": "",
  "section_08_content": "",
  "section_09_title": "",
  "section_09_content": "",
  "key_takeaway_01": "AI code tools increase productivity by 55% but require strict security governance",
  "key_takeaway_02": "Enterprise teams must balance speed gains with vulnerability management",
  "key_takeaway_03": "",
  "paa_01_question": "What are the best AI code generation tools for enterprise teams?",
  "paa_01_answer": "The leading enterprise AI code tools are GitHub Copilot, Amazon Q Developer, and Tabnine. Each serves distinct needs: Copilot excels at general coding with VS Code integration, Amazon Q specializes in AWS-native development, and Tabnine offers air-gapped deployments for security-conscious organizations.",
  "paa_02_question": "How much faster can AI code tools make development?",
  "paa_02_answer": "AI code generation tools can increase developer productivity by 30-55% according to industry studies. GitHub Copilot reports 55% faster task completion, while Tabnine achieved 32% productivity gains at Tesco. Actual results vary based on codebase complexity and team adoption.",
  "paa_03_question": "What security risks come with AI-generated code?",
  "paa_03_answer": "AI-generated code has a 45% vulnerability rate according to NIST security research. Common issues include insecure API calls, missing input validation, and improper error handling. Organizations must implement mandatory code review and automated security scanning for all AI-generated code.",
  "paa_04_question": "",
  "paa_04_answer": "",
  "faq_01_question": "What is the best AI code generation tool for SaaS companies?",
  "faq_01_answer": "The best AI code tool depends on your specific needs. GitHub Copilot offers the broadest IDE integration and highest market adoption. Amazon Q Developer excels for AWS-native applications and legacy migrations. Tabnine provides the strongest privacy controls with air-gapped deployment options.",
  "faq_02_question": "How do AI code tools affect code quality and security?",
  "faq_02_answer": "AI code tools can improve development speed by 30-55%, but introduce security risks. Research shows 45% of AI-generated code contains vulnerabilities requiring manual review. Successful teams implement automated security scanning, mandatory code review, and governance frameworks to balance productivity with quality.",
  "faq_03_question": "What is the cost of implementing AI code generation tools?",
  "faq_03_answer": "AI code tool pricing ranges from $10-20 per developer per month. GitHub Copilot costs $10/month for individuals, Amazon Q Developer starts at $19/month, and Tabnine offers enterprise pricing based on team size. ROI typically comes from 30-55% productivity gains, with most teams seeing payback within 3-6 months.",
  "faq_04_question": "Can AI code tools work with existing development workflows?",
  "faq_04_answer": "Yes, modern AI code tools integrate seamlessly with existing workflows. GitHub Copilot embeds directly into VS Code, Amazon Q integrates with AWS development environments, and Tabnine supports multiple IDEs. Most tools require minimal setup and work alongside existing CI/CD pipelines and version control systems.",
  "faq_05_question": "What are the privacy concerns with AI code generation tools?",
  "faq_05_answer": "Privacy concerns include code being sent to cloud-based AI models, potential IP leakage, and training data exposure. Solutions include air-gapped deployments (Tabnine), on-premise options, and data usage policies. Enterprise teams should evaluate data handling practices and choose tools that align with their security requirements.",
  "faq_06_question": "How do I choose between different AI code generation platforms?",
  "faq_06_answer": "Choose based on your primary needs: GitHub Copilot for general development and VS Code integration, Amazon Q for AWS-native applications and migrations, Tabnine for privacy-focused organizations. Consider factors like IDE support, security requirements, pricing, and team size. Most teams start with a pilot program to evaluate fit.",
  "Sources": "[1]: https://github.blog/2024-09-copilot-enterprise-report/ – GitHub Copilot enterprise productivity study Q3 2024\n[2]: https://www.nist.gov/publications/ai-code-security-2025 – NIST guidelines for secure AI code generation\n[3]: https://aws.amazon.com/blogs/aws/q-developer-java-modernization/ – Amazon Q Developer Java upgrade case study",
  "Search_Queries": "Q1: best AI code generation tools 2025\nQ2: AI code tools security vulnerabilities\nQ3: GitHub Copilot vs Amazon Q Developer comparison"
}}
```

📋 **KEY PATTERNS TO FOLLOW:**

1. **Feature Comparisons** - Use lead-in paragraph + `<ul>` list:
   ```html
   <p>Narrative paragraph introducing comparison [1][2].</p>
   <ul>
     <li><strong>Tool A:</strong> Full description with metrics [3][4]</li>
     <li><strong>Tool B:</strong> Full description with metrics [5][6]</li>
   </ul>
   ```

2. **Case Studies** - Embed in narrative paragraphs:
   ```html
   <p>Context sentence. Company X achieved Y% improvement by doing Z in Q1 2025, 
   with detailed explanation of impact and specific metrics [1][2]. Additional 
   context about why this matters for the industry.</p>
   ```

3. **Natural Paragraphs** - Varied lengths for engaging flow:
   ```html
   <p>Varied length paragraphs create natural rhythm. Use short paragraphs for impact.</p>
   
   <p>Medium paragraphs work well for explanations with supporting details and examples. They provide enough space for a complete thought while remaining scannable.</p>
   ```

VALIDATION RULES (Output will be REJECTED if violated):
1. ❌ **PRIMARY KEYWORD COUNT: "{primary_keyword}" appears 0-4 or 9+ times → REJECTED** (MUST be 5-8)
2. ❌ Any "<p><strong>Label:</strong> [N]</p>" pattern → REJECTED
3. ❌ **MISSING LISTS: Less than 5-8 lists throughout article → REJECTED** (MUST include varied list structures)
4. ❌ **MONOTONOUS PARAGRAPHS: All paragraphs same length → REJECTED** (MUST vary paragraph lengths naturally)
5. ❌ Any case study without Company + Metric + Timeframe → REJECTED
6. ❌ **INTERNAL LINKS: Less than 3 internal links → INSTANT REJECTION** (MUST have minimum 3 `/magazine/` links)
7. ❌ **CONTENT QUALITY VIOLATIONS → INSTANT REJECTION:**
   - Incomplete sentences or broken grammar patterns
   - List items that are sentence fragments or cut off mid-thought
   - Broken patterns like "You can to implement", "What is as we handle"
   - Any content that doesn't make grammatical sense
8. ❌ **FAQ COUNT: Less than 5 FAQ items generated → REJECTED** (MUST have faq_01 through faq_05 with questions and answers)
9. ❌ **PAA COUNT: Less than 3 PAA items generated → REJECTED** (MUST have paa_01 through paa_03 with questions and answers)
10. ✅ Must have 2+ case studies (30+ words each)
11. ✅ Must have natural paragraph variety for engaging flow and readability
12. ✅ Use <ul><li> for feature lists, NEVER standalone <p> labels
13. ✅ **CONTENT QUALITY REQUIREMENTS:**
    - Every sentence must be grammatically complete
    - Every list item must be a complete thought (10-25 words)
    - All content must read naturally and professionally
14. ✅ **INTERNAL LINKING REQUIREMENTS:**
    - Minimum 3 internal links using `/magazine/` prefix
    - Links distributed throughout article (1 every 2-3 sections)
    - Natural anchor text (max 6 words each)

ALWAYS AT ANY TIMES STRICTLY OUTPUT IN THE JSON FORMAT. No extra keys or commentary."""

    return prompt
