Skip to content

Stop Writing YAML: AI Workflows for GitHub Actions

Most devs ask ChatGPT to write YAML, then spend hours debugging syntax errors. Here's why that's backwards - and what actually works.

10 min readIntermediate

Here’s the mistake: you open ChatGPT, paste “write me a GitHub Actions workflow that reviews PRs with AI,” and copy the YAML it spits out. You commit it. Nothing happens.

No error message. No failed run. The workflow just… doesn’t exist, as far as GitHub’s concerned.

Turns out GitHub’s YAML parser rejected it silently. Maybe a duplicate key. Maybe indentation that looks fine but isn’t. The file’s in your repo, but the workflow won’t trigger, and GitHub’s UI won’t always tell you why.

Why asking AI to “just write the YAML” backfires

Most tutorials start with the promise: AI can write your GitHub Actions workflows. Technically true. But they skip the part where you’ll spend the next two hours debugging why the workflow you pasted doesn’t run.

Three failure modes nobody warns you about:

Silent YAML errors. According to community reports, GitHub has tightened its YAML parser over time. Workflows that ran fine six months ago now fail because duplicate keys are no longer tolerated. The catch? GitHub doesn’t always surface the error – it just stops recognizing the file as a valid workflow.

Token limit land mines. You set up a ChatGPT-based code review action. It works great on small PRs. Then someone opens a 50-file refactor, and the action hits OpenAI’s token limit mid-analysis. The review comment posts anyway, but it’s truncated – looks complete, but half the files weren’t checked. You don’t notice until a bug slips through.

The approval gate. As of March 2026, if you’re using GitHub Copilot coding agent to generate PRs, those PRs are treated like contributions from outside collaborators. Your workflows won’t run until someone with write access clicks “Approve and run workflows.” Great for security. Not great if you expected full automation.

The right sequence: validate, then generate

Instead of asking AI to write YAML blind, give it constraints first.

Start with structure. Tell the AI: “I need a workflow that triggers on pull_request, runs on ubuntu-latest, checks out code, and calls an external API. Show me the skeleton.” Verify that skeleton works – commit it, push it, confirm GitHub recognizes it in the Actions tab.

Then add the AI logic in small chunks. One step at a time. After each addition, check the Actions UI. If the workflow disappears, you introduced a syntax error. Roll back, fix it, try again.

This isn’t slower. It’s faster, because you catch breakage immediately instead of debugging a 60-line YAML blob where the error could be anywhere.

Use a YAML validator before you commit

Paste your workflow into an online YAML validator before pushing. Catches duplicate keys, indentation issues, unclosed quotes. Takes 10 seconds. Saves an hour of “why isn’t this running.”

Three paths: ChatGPT API, Copilot CLI, or Agentic Workflows

You’ve got options. Each has trade-offs nobody talks about.

Option 1: Third-party ChatGPT Actions (simplest, least flexible)

The GitHub Marketplace has dozens of actions that call OpenAI’s API for you. You add your OPENAI_API_KEY as a secret, configure a trigger, done.

name: AI Code Review
on:
 pull_request:
 types: [opened, synchronize]
jobs:
 review:
 runs-on: ubuntu-latest
 steps:
 - uses: actions/checkout@v4
 - uses: cirolini/chatgpt-github-actions@v1
 with:
 openai_api_key: ${{ secrets.OPENAI_API_KEY }}
 github_token: ${{ secrets.GITHUB_TOKEN }}
 github_pr_id: ${{ github.event.number }}

The problem? Most of these actions hardcode the prompt. When ChatGPT gives a useless review, you can’t tune it. You’re stuck with whatever the action author thought was a good prompt.

And that token limit issue? Still applies. Large diffs get truncated. The action doesn’t warn you.

Option 2: GitHub Copilot CLI in Actions (official, requires setup)

Per the official documentation, you can run Copilot CLI inside a workflow. You’ll need a personal access token with “Copilot Requests” permission, then install and invoke the CLI programmatically.

- name: Install Copilot CLI
 run: npm install -g @github/copilot

- name: Run Copilot with prompt
 env:
 COPILOT_GITHUB_TOKEN: ${{ secrets.COPILOT_PAT }}
 run: |
 copilot -p "Summarize changes in this PR" > summary.txt

This gives you full control over prompts. You can pipe repository context, PR diffs, test results – whatever Copilot needs to give useful output.

Downside: setup is heavier. You’re managing authentication, CLI installation, and the environment variables Copilot expects. Not hard, but more moving parts than a pre-built action.

Option 3: GitHub Agentic Workflows (newest, Markdown instead of YAML)

This is the part other tutorials haven’t caught up to yet.

As of February 13, 2026, GitHub released Agentic Workflows in technical preview. Instead of writing YAML, you write your workflow goals in plain Markdown. A CLI tool (gh aw) compiles it into a standard GitHub Actions workflow.

Example Markdown workflow:

---
on: pull_request
permissions: read
safe-outputs:
 create-comment:
 body: true
---

Review the PR for logic errors and security issues.
If you find problems, post a comment with details.

You run gh aw compile, and it generates the YAML workflow. The AI agent (GitHub Copilot CLI by default, but supports Claude or OpenAI Codex) reads your natural-language instructions and executes them with safety guardrails – read-only by default, write operations require explicit approval via “safe outputs.”

Why this matters: no YAML syntax errors. You’re writing intent, not configuration. The compiler handles the plumbing.

Pro tip: Agentic Workflows are still in technical preview. Expect rough edges. If you need something production-ready today, stick with Copilot CLI or a third-party action. If you want to experiment with the future of workflow authoring, this is it.

A working example: PR summarizer that doesn’t hit token limits

Let’s build something practical. A workflow that summarizes PR changes without exploding on large diffs.

The trick: don’t send the full diff to the AI. Send file names and change stats first, let the AI decide which files matter, then fetch only those diffs.

name: Smart PR Summary
on:
 pull_request:
 types: [opened]

jobs:
 summarize:
 runs-on: ubuntu-latest
 permissions:
 contents: read
 pull-requests: write
 steps:
 - uses: actions/checkout@v4
 with:
 fetch-depth: 0

 - name: Get changed files
 id: files
 run: |
 git diff --name-status origin/${{ github.base_ref }}...HEAD > changes.txt
 echo "files<> $GITHUB_OUTPUT
 cat changes.txt >> $GITHUB_OUTPUT
 echo "EOF" >> $GITHUB_OUTPUT

 - name: Ask AI which files to review
 id: select
 uses: actions/ai-inference@v2
 with:
 prompt: |
 Here are the changed files:
 ${{ steps.files.outputs.files }}

 Which 5 files are most important to review? Return only file paths, one per line.
 token: ${{ secrets.GITHUB_TOKEN }}
 env:
 GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

 - name: Generate summary
 uses: actions/ai-inference@v2
 with:
 prompt: |
 Summarize the key changes in this PR based on these files:
 ${{ steps.select.outputs.response }}
 token: ${{ secrets.GITHUB_TOKEN }}

 - name: Post summary
 uses: actions/github-script@v7
 with:
 script: |
 await github.rest.issues.createComment({
 owner: context.repo.owner,
 repo: context.repo.repo,
 issue_number: context.issue.number,
 body: process.env.SUMMARY
 })
 env:
 SUMMARY: ${{ steps.select.outputs.response }}

This workflow uses actions/ai-inference, GitHub’s official action for calling AI models. It requires models: read permission in your workflow (add it under permissions if you hit auth errors).

By asking the AI to select files first, you control token usage. Even a 200-file PR won’t blow past limits, because you’re only analyzing the files the AI deems important.

What about accuracy? AI code reviews miss things

They do. A CodeRabbit analysis of 470 open-source PRs found AI-co-authored code introduces 1.7x more issues per 100 PRs than human-written code. Edge cases, null checks, resource cleanup – AI skips them more often.

So why use AI for reviews at all?

Because it catches different things than humans do. Humans miss style inconsistencies, forget to check if new functions have tests, skip reading documentation updates. AI doesn’t get bored. It’ll flag every missing docstring, every function without a test, every TODO comment.

The strategy: AI for breadth, humans for depth. Let the AI handle the mechanical checks (“does this function have a docstring?”), escalate the logic and architecture questions to humans.

Don’t trust AI reviews blindly. Treat them like a junior developer’s feedback – useful, but verify before acting.

Permissions and security: the parts tutorials skip

If your workflow calls an AI model, it’s sending code to an external API. That’s a data leak vector.

What’s being sent? Depends on your prompt. If you’re passing full PR diffs, you’re sending your code to OpenAI (or Anthropic, or wherever the model lives). If your repo is private, that’s your company’s IP leaving GitHub’s infrastructure.

Mitigations:

  • Use GitHub Models when possible. As of August 2025, GitHub Models lets you call leading AI models without data leaving GitHub’s environment. Your code stays on GitHub’s servers.
  • Sanitize prompts. Don’t pass secrets, API keys, or sensitive config files to AI actions. Filter them out before building the prompt.
  • Restrict who can trigger workflows. Use if: github.actor == 'trusted-user' conditions to prevent arbitrary users from running AI workflows that could exfiltrate data via crafted inputs.

And that Copilot approval gate we mentioned? It exists for this reason. PRs from Copilot coding agent don’t auto-run workflows because those workflows might have access to secrets. A malicious prompt could trick Copilot into generating code that exfiltrates GITHUB_TOKEN. The approval step prevents that.

When AI workflows aren’t the answer

Not every automation needs AI.

If your task has a deterministic answer – “run tests,” “lint code,” “deploy to staging” – use regular Actions. AI adds latency (API calls take seconds), costs (OpenAI charges per token), and unpredictability (same input, different output).

AI makes sense when the task requires judgment. Summarizing changes. Suggesting which files to review first. Deciding if a bug report has enough info to be actionable. These don’t have algorithmic solutions.

Here’s a test: if you can write the logic in 20 lines of bash, don’t use AI. If the logic would require reading the code and making a judgment call, AI might help.

Next action: validate one workflow

Pick the simplest AI use case in your repo. Maybe: “Summarize PR changes in a comment.”

Write the YAML skeleton first. Get it triggering. Then add the AI call. Test it on a small PR. Check the output. If it’s useful, keep it. If it’s generic nonsense, tune the prompt or try a different model.

Don’t try to automate everything at once. One workflow. Validate it works. Then decide if it’s worth expanding.

FAQ

Can I use AI to write GitHub Actions workflows from scratch?

Yes, but validate the YAML before committing. AI-generated workflows often have subtle syntax errors that cause silent failures – GitHub won’t show an error, the workflow just won’t trigger. Use a YAML linter and test the workflow in isolation before adding complex logic.

What’s the difference between GitHub Copilot CLI and third-party ChatGPT actions?

Copilot CLI is GitHub’s official tool; it integrates with GitHub’s context (repos, issues, PRs) and runs with your Copilot subscription. Third-party ChatGPT actions use OpenAI’s API directly and require an OpenAI API key. Copilot gives you more control over prompts and context, but requires more setup (PAT, CLI installation). ChatGPT actions are simpler but often have hardcoded prompts you can’t customize. As of February 2026, GitHub Agentic Workflows offer a third option: write workflows in Markdown instead of YAML, compiled via gh aw.

How do I prevent AI workflows from leaking private code?

Three steps: (1) Use GitHub Models instead of external APIs when possible – your code stays on GitHub’s infrastructure. (2) Sanitize prompts to remove secrets, API keys, and sensitive config before passing data to AI. (3) Restrict workflow triggers with conditions like if: github.actor == 'trusted-user' so arbitrary contributors can’t run AI actions. Also note that Copilot coding agent PRs don’t auto-trigger workflows by default; they require manual approval to prevent prompt injection attacks that could exfiltrate secrets.