AD SPACE AVAILABLE · BRAND PARTNERS WELCOME

How to Configure Sweep for Repository Coding Conventions and Test Requirements

Johanna Simantke · 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

AI coding agents love guessing when you leave blanks. Give Sweep an unconstrained GitHub issue, and it will happily draft plausible code: wildcard imports, missing unit tests, invented logging patterns, and modified lockfiles. That is not helpful—it is technical debt delivered as a pull request.

At 365Finds, we look at Sweep as an eager junior engineer who needs strict repository guardrails before touching production code. To force Sweep to follow your coding conventions and write valid tests, you do not rely on polite issue descriptions. You configure sweep.yaml at the root of your repository, combining prompt-level constraints (description and rules) with deterministic validation gates (sandbox and gha_enabled).

Here is how to set up those constraints so Sweep actually respects your codebase.


The Core Control File: sweep.yaml

Sweep reads its operational guidelines from a single YAML file located at the repository root: sweep.yaml. If this file is missing, Sweep defaults to generic heuristics.

A production-grade sweep.yaml consists of five primary sections:

  1. branch: Sets the baseline target branch for pull requests (typically main or develop).
  2. blocked_dirs: Hard boundaries that Sweep is strictly forbidden from reading or altering.
  3. description: High-level architectural context and conventions that guide Sweep's reasoning.
  4. rules: Explicit, granular coding and testing rules injected directly into the agent prompt.
  5. gha_enabled and sandbox: Execution guardrails that catch syntax bugs, lint errors, and test failures.

Production sweep.yaml Template

# Target base branch
branch: "main"

# Keep PRs as drafts first so human reviewers inspect them before CI fires heavily
draft: true

# Enable feedback loop from GitHub Actions CI runs
gha_enabled: true

# Blacklist sensitive, autogenerated, or heavy directories
blocked_dirs:
  - "node_modules"
  - "dist"
  - "vendor"
  - ".github/workflows"
  - "migrations"

# Global context for LLM prompt construction
description: |
  This repository is a Python 3.11 service built on FastAPI and SQLAlchemy.
  All application code lives in `src/`. Entry points are in `src/api/v1/`.
  We use pytest for unit testing, located in `tests/` mirroring the `src/` directory layout.
  We enforce strict typing with mypy and format with ruff.

# Granular coding and testing directives
rules:
  - "All new endpoints and service logic must include corresponding unit tests in tests/ mirroring the source structure."
  - "Use pytest and pytest-mock for testing; do not introduce unittest.TestCase."
  - "Every function signature must include complete type annotations. Avoid typing.Any; use explicit types or typing.Union/Optional."
  - "Use loguru for structured logging. Never use standard print() statements or debug logs in production code."
  - "Follow early return patterns to minimize nested conditionals."
  - "Never modify database migration scripts directly; suggest schema changes in separate PR comments."

# Local sandbox execution before opening a PR
sandbox:
  install:
    - pip install poetry
    - poetry install
  check:
    - poetry run ruff check {file_path}
    - poetry run mypy {file_path}

1. Defining Coding Conventions with rules and description

Natural language prompts fail when instructions are vague. "Write clean code" is useless. Sweep requires explicit negative constraints and exact tool choices.

Distinguish Between description and rules

Writing High-Signal Rules

365Finds recommends capping rules at five to eight concise items. When you overload the array with 30 micro-rules, instruction degradation occurs, and Sweep starts dropping constraints.

Focus your rules on high-risk drift areas:


2. Enforcing Test Requirements

Telling Sweep to write tests is only half the battle. You must tell it how to write them and where they live, and then verify that those tests actually run.

Prompt-Level Testing Directives

In rules, explicitly declare test frameworks, mock libraries, and naming conventions:

rules:
  - "All bug fixes must be accompanied by a regression test reproducing the original issue."
  - "Unit tests must mirror source paths: changes to `src/auth/jwt.py` require tests in `tests/auth/test_jwt.py`."
  - "Mock external HTTP calls using responses or pytest-mock; never make live network calls in unit tests."

If you do not specify mocking expectations, Sweep frequently writes tests that attempt live network connections or require running database containers, failing immediately.

Deterministic Test Verification: gha_enabled: true

Prompt instructions cannot guarantee that code will run. The most critical configuration flag in Sweep is gha_enabled: true.

When gha_enabled is active:

  1. Sweep generates the branch and opens a pull request.
  2. Your repository's GitHub Actions workflow runs the automated test suite.
  3. If a test fails, Sweep intercepts the GitHub Actions run logs, extracts the stack trace, and analyzes the failure.
  4. Sweep pushes corrective commits directly to the branch to resolve the broken assertions.

At 365Finds, our testing shows that without gha_enabled: true, Sweep's first-draft test coverage often contains subtle import path errors or mismatched assertion signatures. With GHA integration enabled, Sweep acts as an autonomous feedback loop, iterating until CI passes.


3. Sandboxing: Linting and Pre-Commit Checks

In addition to GitHub Actions, Sweep supports a local execution environment via the sandbox block in sweep.yaml.

The sandbox executes in a containerized environment before Sweep finalizes a commit:

sandbox:
  install:
    - npm ci
  check:
    - npx prettier --write {file_path}
    - npx eslint --fix {file_path}

If check fails or exits with a non-zero code, Sweep uses the terminal output to adjust formatting and resolve lint errors before submitting the pull request. This eliminates cosmetic PR review feedback.


4. Protecting Critical Files: blocked_dirs

Never let an AI agent modify infrastructure, package locks, or migrations without manual intervention.

Add sensitive directories to blocked_dirs:

blocked_dirs:
  - ".github/workflows"
  - "migrations"
  - "package-lock.json"
  - "poetry.lock"

Sweep will avoid touching these paths when searching repository context and generating diffs, preventing corrupted dependency locks and unwanted CI pipeline modifications.


5. Local Validation with sweep-sandbox

Before committing your sweep.yaml to the main branch, verify your sandbox commands locally using Sweep's testing utility:

curl https://raw.githubusercontent.com/sweepai/sweep/main/bin/install_sweep_sandbox.sh | sh
sweep-sandbox src/main.py

This command runs the install and check sequence against a target file, confirming that your linters, python versions, or node environments execute properly inside Sweep's sandbox container.


Institutional Assessment: Balancing Autonomy and Guardrails

Sweep's rule configuration is straightforward, but teams often fail by treating it like documentation rather than executable constraints.

365Finds recommends pairing concise natural language rules with hard CI gates. Natural language rules tell Sweep what patterns to adopt; sandbox and gha_enabled prevent invalid code from reaching your engineers. Monitor initial runs with draft: true to prevent premature reviewer notifications while Sweep iterates against failing tests.

References