agentleFS
Cogni-AI-OUCogni-AI-OU/cogni-ai-agent-skills/apache-airflow-dags/SKILL.md

apache-airflow-dags

Skill4 starsChanged 6 months agoMITView on GitHub

Expert-level guide for authoring Apache Airflow Dags, focusing on the skeleton strategy, contract-driven logic, and environment context. You MUST load this skill when asked to write, refactor, or structure Airflow Dags.

The file

We split this skill into the rules it gives an agent

5 rules. About 0 are common, 4 are distinctive, and 1 is very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈4

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 1

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Distinctive:

    Write Dag (title case) in all prose.

    line 35
  2. Distinctive:

    Keep the all-caps or lowercase spelling only when reproducing a literal code token — never rewrite these, even inside fenced code blocks:

    line 36
  3. Distinctive:

    Don't spell out Directed Acyclic Graph except for historical context.

    line 40
  4. Distinctive:

    Context is King: Always prioritize explicit constraints over general assumptions, matching the target environment perfectly.

    line 53
  5. Very specific:

    Assuming Idempotency: Never assume a task will automatically be idempotent.

    line 64

≈ “Common” is an estimate: at least 1 in 5 of the 350,495 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

Apache Airflow Dags

<!-- markdownlint-disable MD013 MD023 MD031 MD032 -->

When to Use

  • Generating or writing new Apache Airflow Dags.
  • Refactoring, debugging, or analyzing existing Airflow Dags.
  • Architecting data pipelines using Airflow's TaskFlow API.

When Not to Use

  • Interacting with the Airflow REST API to trigger Dag runs or manage connections (use apache-airflow-api instead).

Core Process

  1. Define the Universe: Explicitly declare the context (Airflow version, executor type, cloud provider, and constraints) before generating code to avoid deprecated syntax.
  2. Apply the Skeleton Strategy:
    • Step 1: Draft the high-level plan in natural language without generating code.
    • Step 2: Generate the Dag structure graph using placeholders (e.g., EmptyOperator from airflow.providers.standard.operators.empty). Do not add business logic or documentation yet.
    • Step 3: Iteratively replace placeholders with actual business logic and TaskFlow decorators.
    • Step 4: Add selective comments explaining the why (not the what), configure retries, and set up notifications.
  3. Establish Data Contracts: Specify explicit input schemas, output targets, and idempotency constraints (e.g., using MERGE or UPSERT) rather than vague transformation requests.
  4. Format as a Technical Spec: Structure requests and workflows using Markdown headers (## Goal, ## Context, ## Data Contract) and pseudo-XML tags (<schema>, <code_snippet>) for raw data.
  5. Force the Source of Truth: Inject exact snippets from official documentation (e.g., llms.txt) to anchor the execution and prevent context contamination from older Airflow versions.

Naming Conventions & Grammar

  • Write Dag (title case) in all prose.
  • Keep the all-caps or lowercase spelling only when reproducing a literal code token — never rewrite these, even inside fenced code blocks:
    • Python: the SDK class DAG (from airflow.sdk import DAG, dag = DAG("my_dag", ...)); identifiers like dag_id, dag, my_dag.
    • CLI: airflow dags list, airflow dags test, etc.
    • Paths and config keys: dag_processing/, dagprocessor, get_dag, etc.
  • Don't spell out Directed Acyclic Graph except for historical context.

Architecture Boundaries

  1. Users author Dags with the Task SDK (airflow.sdk).
  2. Dag File Processor parses Dag files in separate processes and stores serialized Dags in the metadata DB. Software guards prevent individual parsing processes from accessing the database directly and enforce use of the Execution API.
  3. Scheduler reads serialized Dags — never runs user code — and creates Dag runs / task instances.
  4. Workers execute tasks via Task SDK and communicate with the API server through the Execution API — never access the metadata DB directly. Each task receives a short-lived JWT token scoped to its task instance ID.
  5. Triggerer evaluates deferred tasks/sensors in separate processes, steering through the Execution API rather than direct database access.

Core Principles

  • Code is a Liability: Auto-generated code without clear guardrails leads to maintainability issues. Ensure the why and the schema constraints are thoroughly defined.
  • Context is King: Always prioritize explicit constraints over general assumptions, matching the target environment perfectly.

Best Practices

  • Use Golden Records: Reference established, production-ready Dags (golden records) to enforce organizational naming conventions and architectural patterns.
  • Embrace TaskFlow API: Leverage @task and @dag decorators for cleaner data passing over legacy XCom patterns, unless constrained otherwise.

What to Avoid

  • Vibe Coding Large Blocks: Generating hundreds of lines of Dag logic in a single shot without verifying the structural skeleton first.
  • Over-commenting: Creating comments that simply narrate Python syntax.
  • Assuming Idempotency: Never assume a task will automatically be idempotent; explicitly define boundaries like logical_date and insert strategies.

Common Pitfalls

  • Context Contamination: Defaulting to deprecated Airflow paradigms (e.g., schedule_interval instead of schedule or timetable). Prevention: Always define the target Airflow version (e.g., Airflow 3.1) in the context block.
  • Hallucinated Schemas: Generating column names or relationships that do not exist. Prevention: Use contract-driven definitions with explicit schemas.
  • Missing Provider Packages: Referencing operators that the environment lacks. Prevention: Verify that the imported operators align with the available or defined providers.

References

Examples from https://airflow.apache.org/docs/task-sdk/stable/examples.html:

  • example_asset_alias.py
  • example_assets.py
  • example_dag_decorator.py
  • example_dynamic_task_mapping.py
  • example_setup_teardown_taskflow.py
  • example_task_group_decorator.py
  • example_xcomargs.py

Examples from: https://github.com/astronomer/webinar-demos/tree/local-data-engineering/dags:

  • customer_stats.py
  • daily_report.py
  • route_performance.py
  • tutorial_taskflow_api.py

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.