Systems Library / Operations & Admin / How to Build an AI Process Documentation Generator
Operations & Admin process workflow

How to Build an AI Process Documentation Generator

Generate process documentation automatically from workflow execution data.

Jay Banlasan

Jay Banlasan

The AI Systems Guy

Nobody documents their processes until something breaks. I built an ai process documentation generator that watches how your team actually works, records the steps, and produces formatted documentation automatically. Documentation from real execution data, not guesswork.

The system writes the docs by observing the work.

What You Need Before Starting

Step 1: Collect Execution Data

import sqlite3
from datetime import datetime

def init_doc_db(db_path="process_docs.db"):
    conn = sqlite3.connect(db_path)
    conn.execute("""
        CREATE TABLE IF NOT EXISTS execution_logs (
            id INTEGER PRIMARY KEY AUTOINCREMENT,
            process_name TEXT,
            step_name TEXT,
            step_order INTEGER,
            actor TEXT,
            tools_used TEXT,
            input_data TEXT,
            output_data TEXT,
            duration_minutes REAL,
            notes TEXT,
            logged_at TEXT
        )
    """)
    conn.commit()
    return conn

def log_execution_step(conn, process_name, step_name, order, actor, tools, notes=""):
    conn.execute(
        "INSERT INTO execution_logs VALUES (NULL,?,?,?,?,?,?,?,?,?,?)",
        (process_name, step_name, order, actor, tools, "", "", 0, notes, datetime.now().isoformat())
    )
    conn.commit()

Step 2: Aggregate Process Patterns

def aggregate_process(conn, process_name, min_executions=3):
    rows = conn.execute("""
        SELECT step_name, step_order, actor, tools_used, notes,
               COUNT(*) as frequency
        FROM execution_logs
        WHERE process_name = ?
        GROUP BY step_name, step_order
        HAVING frequency >= ?
        ORDER BY step_order
    """, (process_name, min_executions)).fetchall()

    steps = []
    for row in rows:
        steps.append({
            "step": row[0], "order": row[1], "typical_actor": row[2],
            "tools": row[3], "notes": row[4], "frequency": row[5]
        })
    return steps

Step 3: Generate Documentation with AI

import anthropic
import json

client = anthropic.Anthropic()

def generate_process_doc(process_name, aggregated_steps):
    prompt = f"""Generate process documentation from this execution data.
This data represents how the team actually performs the "{process_name}" process.

Execution data (steps in order with frequency):
{json.dumps(aggregated_steps, indent=2)}

Write a complete process document with:
1. Process Overview (2-3 sentences)
2. When to Use This Process
3. Roles Involved
4. Tools Required
5. Step-by-Step Procedure (numbered, with tool references)
6. Common Variations (based on notes and frequency patterns)
7. Troubleshooting Tips

Write for someone performing this process for the first time.
Keep steps actionable. One action per step."""

    message = client.messages.create(
        model="claude-sonnet-4-20250514",
        max_tokens=3000,
        messages=[{"role": "user", "content": prompt}]
    )
    return message.content[0].text

Step 4: Detect Process Variations

def detect_variations(conn, process_name):
    instances = conn.execute("""
        SELECT DISTINCT
            GROUP_CONCAT(step_name, ' -> ') as path
        FROM execution_logs
        WHERE process_name = ?
        GROUP BY logged_at
    """, (process_name,)).fetchall()

    paths = {}
    for (path,) in instances:
        paths[path] = paths.get(path, 0) + 1

    sorted_paths = sorted(paths.items(), key=lambda x: -x[1])
    return {
        "primary_path": sorted_paths[0] if sorted_paths else None,
        "variations": sorted_paths[1:],
        "total_variations": len(sorted_paths)
    }

Step 5: Keep Documentation Updated

def check_for_drift(conn, process_name, current_doc_date):
    recent_executions = conn.execute("""
        SELECT step_name, step_order, COUNT(*) as freq
        FROM execution_logs
        WHERE process_name = ? AND logged_at > ?
        GROUP BY step_name, step_order
        ORDER BY step_order
    """, (process_name, current_doc_date)).fetchall()

    new_steps = []
    for name, order, freq in recent_executions:
        existing = conn.execute("""
            SELECT COUNT(*) FROM execution_logs
            WHERE process_name=? AND step_name=? AND logged_at < ?
        """, (process_name, name, current_doc_date)).fetchone()[0]

        if existing == 0 and freq >= 3:
            new_steps.append({"step": name, "order": order, "frequency": freq})

    if new_steps:
        print(f"Process drift detected in '{process_name}': {len(new_steps)} new steps found")
    return new_steps

What to Build Next

Add a diff view that shows how the process changed between documentation versions. When the team starts doing something differently, the system should surface what changed and ask if the documentation needs updating.

Related Reading

Want this system built for your business?

Get a free assessment. We will map every system your business needs and show you the ROI.

Get Your Free Assessment

Related Systems