Skip to main content
ai-slop/python-print-debugmanual fix

Print debugging.

A `print()` call left in library or application code. Usually a trace from a debugging session that shipped.

Flagged shape and clean shape.

Each example shows the exact code shape the rule is looking for, then the smallest version that keeps the intent without hiding risk or adding noise.

python-print-debug.py
✗ Flagged
def apply_discount(cart, code):
    print("cart before", cart)
    discount = lookup_discount(code)
    print("discount", discount)
    cart.total -= discount.amount
    return cart
Why this trips

Deterministic line match: flags statements that begin with `print(`, outside comments and triple-quoted strings.

python-print-debug.py
✓ Clean
logger = logging.getLogger(__name__)

def apply_discount(cart, code):
    discount = lookup_discount(code)
    logger.debug("applying discount %s to cart %s", code, cart.id)
    cart.total -= discount.amount
    return cart
What changed

Remove the print or replace it with `logging.getLogger(__name__)` at the right level. For a genuine CLI entry point, move it to `__main__.py` or `scripts/` so the rule skips it.

Agents debug by printing intermediate values, then forget to remove the prints once the code works. The output lands on stdout in production, unstructured and without a level.

How this rule is justified.

Rule id

ai-slop/python-print-debug

Enforcing engine

ai-slop

Detector strategy

Deterministic line match: flags statements that begin with `print(`, outside comments and triple-quoted strings.

Legitimate code that is NOT flagged

Test files, `__main__.py`, `manage.py`, `setup.py`, `tutorial*.py`, files with an `if __name__ == "__main__":` guard, and files under `scripts/`, `bin/`, `docs/`, or `examples/` are not flagged.

Evidence

Shipped with aislop's v0.8.0 Python detectors, listed in the release notes as generic print debugging.