Skip to content

E-Lab Script Generator with Airtable Loop

This workflow generates WhatsApp-based mentor preparation scripts for Educate! programs, featuring comprehensive validation, iterative improvement, and detailed logging. It accepts lesson parameters via webhook, generates scripts using AI agents, validates the output against strict formatting requirements, and can automatically retry up to 3 times to fix validation errors.

Purpose

No business context provided yet — add a context.md to enrich this documentation.

How It Works

  1. Input Reception: Webhook receives lesson details including name, objectives, duration, outline, characters, and special requirements
  2. Input Validation: Validates required fields and ensures proper character selection (Guide, Practitioner, Challenger are mandatory)
  3. Guidelines Retrieval: Fetches the latest script formatting guidelines from Google Docs
  4. Script Generation: AI agent generates a 15-segment WhatsApp script following specific format requirements
  5. Validation Process: Comprehensive validation checks for proper structure, character usage, segment count, and formatting
  6. Iterative Improvement: If validation fails and attempts < 3, the system automatically retries with specific error feedback
  7. Logging: All attempts, results, and metrics are logged to Airtable for tracking and analysis
  8. Response: Returns either the successful script with metrics or error details after maximum attempts

Mermaid Diagram

graph TD
    A[Webhook] --> B[Validate Input]
    B --> C[Get Guidelines from Google Docs]
    C --> D[Prepare Agent Input]
    D --> E[Script Writer Agent]
    E --> F[Evaluation]
    F --> G[Create/Update Airtable Record]
    G --> H{Check If Passed}
    H -->|Yes| I[Calculate Final Metrics]
    I --> J[Respond Success]
    H -->|No| K{Check Max Attempts}
    K -->|< 3 attempts| L[Fetch From Airtable]
    L --> M[Build Rewrite Prompt]
    M --> N[Update Attempt Context]
    N --> E
    K -->|>= 3 attempts| O[Respond Max Attempts Error]

    P[Webhook2] --> Q[Validate Input2]
    Q --> R[Extract from File]
    R --> S[Get Guidelines from Google Docs]
    S --> T[Prepare Agent Input1]
    T --> U[Script Writer Agent1]
    U --> V[Create/Update Airtable Record1]
    V --> W[Respond Success1]

Trigger

Webhook: POST endpoint at /elab-generator that accepts lesson parameters including: - lessonName: Name of the lesson - objectives: Learning objectives - duration: Target duration in minutes - outline: Content outline - characters: Array of character names (must include Guide, Practitioner, Challenger) - special: Special requirements (optional) - tone: Script tone (optional, defaults to "conversational") - sourceFiles: Uploaded lesson materials (optional)

Nodes Used

Node Type Purpose
Webhook Receives lesson parameters via HTTP POST
Code (JavaScript) Validates input, processes data, calculates metrics
Google Docs Retrieves script formatting guidelines
AI Agent Generates and rewrites scripts using language models
OpenRouter Chat Model Provides AI language model capabilities
Airtable Logs generation attempts and results
Respond to Webhook Returns final results or errors
If (Conditional) Controls flow based on validation results and attempt counts
Set Prepares data for subsequent nodes
Extract from File Processes uploaded lesson materials

External Services & Credentials Required

  • OpenRouter API: For AI language model access (Claude 3.7 Sonnet)
  • Google Docs API: To fetch formatting guidelines document
  • Airtable API: For logging script generation attempts and results

Required credentials: - OpenRouter API key - Google OAuth2 credentials for Docs access - Airtable Personal Access Token

Environment Variables

No specific environment variables are documented in the workflow configuration.

Data Flow

Input: - Lesson name, objectives, duration, outline - Character selection (minimum 3, including required characters) - Optional special requirements and tone preferences - Optional source files for additional context

Output: - Success: Generated script with metrics (word count, segment count, estimated duration) - Failure: Error details after maximum retry attempts - Logging: All attempts stored in Airtable with detailed validation results

Error Handling

The workflow includes sophisticated error handling:

  1. Input Validation: Checks for required fields and proper character selection
  2. Script Validation: 9-point validation system checking:

    • Proper intro audio placement
    • Correct segment count (14-16 segments)
    • Required dialogue segments (4-6)
    • Character presence verification
    • Word count targets (2,500-4,000 words)
    • Visual asset requirements
    • Proper formatting structure
  3. Retry Mechanism: Up to 3 attempts with specific error feedback for improvements

  4. Graceful Degradation: Returns detailed error information when all attempts fail

Known Limitations

  • Maximum 3 retry attempts for script generation
  • Requires specific character selection (Guide, Practitioner, Challenger mandatory)
  • Target word count range of 2,500-4,000 words
  • Dependent on external Google Docs for guidelines
  • File processing limited to basic text extraction

No related workflows are mentioned in the provided context.

Setup Instructions

  1. Import Workflow: Import the JSON configuration into your n8n instance
  2. Configure Credentials:
    • Set up OpenRouter API credentials with access to Claude 3.7 Sonnet
    • Configure Google OAuth2 for Docs API access
    • Add Airtable Personal Access Token
  3. Update References:
    • Update Google Docs URL to your guidelines document
    • Configure Airtable base and table IDs for logging
  4. Test Webhook: Verify webhook endpoint is accessible and properly configured
  5. Validate Guidelines: Ensure the Google Docs guidelines document is properly formatted and accessible
  6. Test Generation: Send a test request with all required parameters to verify functionality

The workflow is designed to be production-ready with comprehensive error handling and detailed logging for monitoring and improvement.