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:
branch: Sets the baseline target branch for pull requests (typicallymainordevelop).blocked_dirs: Hard boundaries that Sweep is strictly forbidden from reading or altering.description: High-level architectural context and conventions that guide Sweep's reasoning.rules: Explicit, granular coding and testing rules injected directly into the agent prompt.gha_enabledandsandbox: 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
descriptionprovides the map: Use it to explain architecture, module boundaries, and established libraries. For example: "All database queries must go through the repository layer insrc/repositories/."rulesenforce behavioral contracts: This is an array of short, imperative strings. Each rule is treated as a priority constraint during Sweep's code synthesis phase.
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:
- Typing Standards:
"Never use 'any' in TypeScript; use strict interfaces."or"Use typing.Sequence instead of typing.List in argument annotations." - Logging and Diagnostics:
"Do not leave console.log or print statements in generated code." - Library Boundaries:
"Use Dayjs for date manipulation; do not import moment.js." - Error Handling:
"Raise custom AppError instances from src/exceptions.py instead of generic ValueError."
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:
- Sweep generates the branch and opens a pull request.
- Your repository's GitHub Actions workflow runs the automated test suite.
- If a test fails, Sweep intercepts the GitHub Actions run logs, extracts the stack trace, and analyzes the failure.
- 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:
install: Runs once to configure dependencies (e.g.,poetry installornpm ci).check: Executes linters or formatters across modified files using the{file_path}placeholder.
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.