Automation Blog

How to Use AI to Document Zapier Code Steps with Comments

Code steps without comments are a maintenance problem — six months later, nobody remembers what a particular line does or why it was written that way. AI assistants can annotate existing Code step code with clear, useful inline comments in seconds.

ZapierAICode Steps

By Troy Tessalone · · 3 minutes

Automation Guide

A practical field guide from Automation Ace.

How to Use AI to Document Zapier Code Steps with Comments

Undocumented Code steps are a quiet source of maintenance pain in Zapier-based systems. A Code step that makes perfect sense when it's written becomes opaque when the person who wrote it leaves, or when you return to it six months later to update an API endpoint. AI assistants can add inline comments to existing Code step code quickly — explaining what each section does, why specific approaches were chosen, and what the inputs and outputs represent. This takes a minute and pays dividends every time someone reads the code later.

Prompt: Add Comments to Existing Code

The simplest version:

"Add clear inline comments to this Zapier JavaScript Code step. Comments should explain what each section does, what the input data fields represent, why specific methods were chosen (e.g. why URLSearchParams instead of string concatenation), and what each output field contains. Keep comments concise — one line per non-obvious operation. Here is the code: [paste code here]"

For Python Code steps, the prompt is identical — just specify Python.

Example: Before and After

Before (no comments):

const params = new URLSearchParams({
  email: inputData.email,
  status: 'active'
});

const response = await fetch(`https://api.example.com/contacts?${params}`, {
  headers: { 'Authorization': 'Bearer ' + inputData.api_token }
});

if (!response.ok) throw new Error(`${response.status}: ${await response.text()}`);

const data = await response.json();
const contact = data.results?.[0];

output = {
  id: contact?.id ? String(contact.id) : '',
  name: contact?.name || '',
  found: contact ? 'true' : 'false'
};

After prompting AI to add comments:

// Build query parameters using URLSearchParams to handle special characters
// (e.g. + in email addresses) safely — avoids manual string concatenation
const params = new URLSearchParams({
  email: inputData.email,  // email to look up, mapped from trigger
  status: 'active'         // only return active contacts
});

// GET request to the contacts search endpoint with Bearer token auth
const response = await fetch(`https://api.example.com/contacts?${params}`, {
  headers: { 'Authorization': 'Bearer ' + inputData.api_token }
});

// Throw a descriptive error on non-2xx responses so Zapier shows the issue
if (!response.ok) throw new Error(`${response.status}: ${await response.text()}`);

const data = await response.json();
// Take the first result; the API returns results[] sorted by relevance
const contact = data.results?.[0];

output = {
  id: contact?.id ? String(contact.id) : '',  // convert numeric ID to string
  name: contact?.name || '',
  found: contact ? 'true' : 'false'  // string 'true'/'false' for Filter step compatibility
};

Asking for a Header Comment Block

For longer Code steps, a header block at the top describing the step's purpose is useful for team documentation:

"Add a comment block at the top of this Zapier Code step (before any code) that documents: what the step does, what each input data field contains and where it comes from, what each output field contains and how it's used, and any important notes about edge cases or API behavior. Then add brief inline comments throughout. Here is the code: [paste code]"

This produces something like:

/*
 * Zapier Code Step: Look Up Contact by Email
 *
 * Purpose: Searches the Example API for a contact matching the trigger email.
 *          Returns the contact ID and name for use in the next step.
 *
 * Input Data:
 *   inputData.email     - Contact email from the form trigger
 *   inputData.api_token - Example API Bearer token (stored as static value)
 *
 * Output Fields:
 *   id    - Contact's numeric ID as string (empty if not found)
 *   name  - Contact's display name (empty if not found)
 *   found - 'true' if a contact was found, 'false' otherwise
 *
 * Notes:
 *   - API returns up to 10 results; we take the first match only
 *   - 404 is treated as "not found", not as an error
 */

Controlling Comment Verbosity

AI tends to over-comment obvious lines (// increment i by 1) and under-comment subtle ones. Add to your prompt:

  • "Skip comments for self-explanatory lines like variable declarations with clear names."
  • "Focus comments on why something is done this way, not just what it does."
  • "Add a comment for every API interaction, every error handling block, and every output field."

Using Commented Code as a Template

Once you have a well-commented Code step, it doubles as a template for future steps with similar patterns. The comments explain the structure well enough that a non-developer can adapt the key values (endpoint URL, field names, output fields) without needing to understand every line.

Adding comments to a Code step is a five-minute investment that protects hours of debugging later. AI makes it trivial — paste the code, ask for comments, paste the result back. The documentation cost is now close to zero, so there's no excuse for leaving Code steps undocumented.

For asking AI to explain what a Code step does in plain language, see using AI to explain Zapier code snippets. For asking AI to generate new Code step code from scratch, see using AI to generate JavaScript or Python for Zapier. For help auditing and documenting an existing Zapier system, talk to Automation Ace.

ZapierAICode Steps

Disclaimer: This article may include links to apps, products, or services. Some links may be affiliate links, which means Automation Ace may earn a commission at no extra cost to you.

Build Better Systems

Ready to automate with confidence?

Share your tools, process, and goals. Automation Ace can design the workflow, integration, AI assist, or code bridge that fits your business.

Start a Project