← Tous les articles

Debugging with AI: redact logs and data before sharing them with an assistant

Pasting an error log into an AI assistant saves time, but those lines often carry customer emails, tokens and IP addresses. Here is the small script and the habits we rely on to give the assistant useful context without leaking anything.

Debugging with AI: redact logs and data before sharing them with an assistant

Key points

  • Production logs nearly always contain personal data or secrets, so clean them before sharing.
  • Consistent pseudonyms (same email, same alias) keep the log useful for the AI.
  • For database questions, the schema and a handful of hand-picked rows are enough.

Asking a coding assistant to explain an error from the raw log has become second nature for many teams, ours included. The catch is what that log contains. When we started reading what we were about to paste, we found customer email addresses, full Authorization headers, test-mode payment keys and once a password passed as a URL parameter by an old plugin. None of it helps the model understand the bug. Here is how we keep the benefit and drop the risk.

What should never leave your machine

  • Your .env, wp-config.php or any config file. Describe the variables instead.
  • A full database dump, even “just to reproduce it locally”.
  • Tokens, API keys, session cookies and auth headers, test ones included.
  • Customer personal data: names, emails, phone numbers, addresses, IPs.

If a secret slips through, treat it as compromised and rotate it. You do not control what happens to it once sent, and retention terms vary by tool and plan, so check the ones that apply to your subscription.

A cleanup script before every paste

We keep a small script in each project. It swaps secrets for markers and turns every email address into a stable alias. The same customer always becomes user3@example.test, so you can still follow their journey through the log.

#!/usr/bin/env python3
# Usage: python3 redact.py < error.log > error-clean.log
import re
import sys

emails = {}

def pseudo_email(m):
    # Same address -> same placeholder, so the AI can still follow a user
    return emails.setdefault(m.group(0), f"user{len(emails) + 1}@example.test")

RULES = [
    (re.compile(r"(?i)((?:api[_-]?key|secret|password|passwd|token)["']?s*[:=]s*["']?)[^"'s,&]+"),
     r"1<redacted>"),
    (re.compile(r"(?i)b(bearer)s+[A-Za-z0-9._~+/=-]+"), r"1 <token>"),
    (re.compile(r"bsk_(?:live|test)_[A-Za-z0-9]+"), "<stripe_key>"),
    (re.compile(r"b(?:d{1,3}.){3}d{1,3}b"), "<ip>"),
]
EMAIL = re.compile(r"[w.+-]+@[w-]+(?:.[w-]+)+")

for line in sys.stdin:
    for pattern, repl in RULES:
        line = pattern.sub(repl, line)
    sys.stdout.write(EMAIL.sub(pseudo_email, line))

These patterns cover what we run into most often, not everything. Extend them for your own formats, such as order references tied to a name or your providers’ key prefixes, and always glance at the output before pasting. The script lowers the risk; it does not replace a quick read.

For database issues

The model needs the table structure and the shape of the data, not real records. The schema plus a few rows you have checked by hand covers nearly every question.

# Table structure only, no rows
mysqldump --no-data --skip-comments shop orders order_items > schema.sql

# A few rows you have checked by hand, for realistic examples
mysql shop -e "SELECT id, status, total, created_at FROM orders
               WHERE status = 'failed' LIMIT 5" > sample.tsv

When you need realistic volumes, ask the assistant to generate fake data from the schema. On our projects that same approach feeds demo environments, so production is never copied.

Context that actually helps

What you remove in data, make up for in context: PHP and WordPress versions, the relevant code excerpt, what changed since the last working release, and steps to reproduce. A short, clean log with that information gets better answers than thousands of lines pasted as is.

FAQ

Is pseudonymisation enough for GDPR?

It cuts the risk significantly, but pseudonymised data can be re-identified if the mapping is kept. Share only what is needed and check your tool’s processing terms with whoever handles data protection.

Does a locally hosted model solve the problem?

It avoids sending data to a third party, which matters a lot. Secrets should still stay out of what you feed it, if only so they do not end up in a chat history.

Want to bring AI into your development workflow without putting customer data at risk? We help teams choose the tools, set the rules and build the supporting tooling.

Partager LinkedIn Facebook X WhatsApp
</>

webtestudio

Agence web : sites WordPress sur mesure, thèmes premium et logiciels SaaS.

Parler de votre projet →