AD SPACE AVAILABLE · BRAND PARTNERS WELCOME

Enforcing Team Coding Conventions with Sweep: The sweep.yaml Guide

小森夏平 · 365Finds Editorial
Indexed 88,650 Wiki articles

Put 365 Wiki to work with your AI

Copy the prompt below, paste it into the AI you already use, then ask your question.

Download full Skill

Try it with the prompt first. If you use 365 Wiki often, install the full 365Wiki Skill so you do not have to paste it again. No regular AI? Gemini or Microsoft Copilot on the web will work.

365Wiki Skill

Autonomous AI coding agents present a specific operational hazard: left unguided, they write code that compiles, passes superficial checks, and completely disregards your repository's established conventions. They invent new helper utilities when canonical ones already exist, pull in unsolicited third-party dependencies, skip unit tests, and format code according to whatever public repositories dominated their training sets.

For teams running Sweep—an AI developer that turns GitHub issues into complete pull requests—the primary mechanism to prevent this style drift is sweep.yaml. Placed at the root of a repository, this configuration file establishes explicit boundaries, architectural context, and natural-language coding rules that govern Sweep's code generation, planning, and validation stages.

At 365Finds, we look at developer automation tools through a pragmatic lens: an AI agent that saves ten minutes writing a routine feature but costs twenty minutes in code-review cleanup is a net negative. Here is our breakdown of how sweep.yaml works, how to configure repository rules to enforce coding conventions, and where its limits lie.


The Anatomy of sweep.yaml

Sweep reads sweep.yaml directly from the base branch on every triggered task. While the file supports several operational flags, five core parameters directly shape code quality and stylistic alignment:

KeyTypeOperational Impact on Conventions
rulesArray of stringsDirect, high-priority instructions injected into the agent's context during planning, code modification, and review.
descriptionStringGlobal architectural context defining your tech stack, framework versions, directory patterns, and primary entry points.
blocked_dirsArray of stringsStrict path boundaries preventing Sweep from reading or modifying legacy, vendor, or generated directories.
sandboxObject (install, check)Sandboxed execution commands that run formatters, linters, and test suites immediately after file edits.
gha_enabledBooleanAllows Sweep to parse GitHub Actions logs and self-correct when continuous integration tests fail.
# sweep.yaml - Production baseline for full-stack repositories
branch: "main"
draft: false
gha_enabled: true

description: "Python 3.11 backend with FastAPI and SQLAlchemy 2.0; TypeScript React frontend. Business logic resides strictly in src/services/."

blocked_dirs:
  - "legacy/"
  - "alembic/versions/"
  - "frontend/build/"

rules:
  # Style & Formatting
  - "All Python functions must have explicit type annotations for parameters and return values; use built-in generics (list, dict) rather than typing module aliases."
  - "Never use wildcard imports (e.g., from module import *)."
  - "Remove all temporary print statements, debug logging, and obvious explanatory comments before submitting."

  # Dependencies & Architecture
  - "Use loguru for application logging. In except blocks, call logger.exception() to preserve stack traces."
  - "Do not introduce new external libraries or packages without updating pyproject.toml and documenting the rationale in the pull request description."
  - "All database mutations must use existing SQLAlchemy session dependencies; never open raw engine connections."

  # Unit Testing Requirements
  - "Every new business function in src/services/ must have an accompanying pytest test suite located in tests/."
  - "Mock external HTTP requests using responses or pytest-mock; never execute live network requests during test runs."
  - "Aim for complete boundary condition coverage, including null inputs, invalid payloads, and timeout scenarios."

sandbox:
  install:
    - poetry install --no-interaction
  check:
    - ruff check {file_path}
    - pytest {file_path}

How Repository Rules Shape Agent Behavior

The rules block is not merely documentation; Sweep parses these items as active constraints during each phase of execution.

1. Style and Idiom Constraints

General LLM models often default to generic, verbose code patterns. In Python, for instance, an agent might mix typing.List with modern built-in list[] syntax, or leave trivial inline comments like # increments counter.

By framing rules as declarative negatives and explicit standards, you eliminate predictable style review bikeshedding:

2. Dependency and Architectural Boundaries

One of the most dangerous tendencies of automated coding bots is "dependency hallucination"—importing libraries that seem logical to the model but bloat your dependency tree or clash with internal architectural standards.

When you specify dependencies explicitly in rules, Sweep restricts itself to chosen frameworks:

3. Unit Testing and Verification Rigor

Left unprompted, an AI developer will resolve an issue, check if the file syntax is valid, and immediately declare victory. In a mature repository, untracked code without regression coverage is technical debt.

Specifying testing requirements in rules compels Sweep to write both production code and test files in the same pull request:


Layering Natural Language with Deterministic Checks

Here is 365Finds' definitive stance on sweep.yaml: natural language rules are soft guardrails, not deterministic compilers.

If you rely solely on natural language statements like "Write clean, readable code", Sweep will interpret that ambiguity through statistical probability, leading to inconsistent outputs across different runs. The real power of sweep.yaml emerges when you combine the rules array with deterministic feedback loops:

  1. The sandbox directive: By defining sandbox.check commands (such as running ruff check {file_path} or prettier --check), Sweep runs your team's exact formatters against the modified file inside an isolated execution environment before opening the PR.
  2. The gha_enabled flag: When set to true, Sweep does not stop when code is pushed. If your GitHub Actions CI pipeline fails on linting, type checks (tsc or mypy), or test failures, Sweep reads the CI logs, analyzes the failure backtraces, and automatically pushes corrective commits to the branch.

This three-tier structure—rules for intent, sandbox for pre-flight validation, and gha_enabled for CI healing—transforms Sweep from a reckless code generator into a disciplined contributor.


365Finds Recommendation and Best Practices

For engineering leads introducing Sweep to their workflow, 365Finds recommends treating sweep.yaml exactly like an onboarding runbook for an intern:

Sweep cannot infer unwritten engineering culture. If your team cares about typing discipline, structured error logs, and defensive unit testing, encode those expectations into sweep.yaml from day one.

References