Work effectively with AI coding agents. Understand them as language models running in a tool loop with limited context, which is why they guess, game the visible signal and report confidently. Recognise the shortcut and correctness tells in their code across Python, TypeScript/JavaScript, Rust, Java and Go, and know the damage each one does later. Verify changes instead of trusting them, review diffs fast for quality and security, judge when work is truly finished, and choose, design and steer tasks so agents can finish them well.
Pin behavior before a refactor card 5 of 6

The pins catch what the agent's tests missed

builds on: Refactors that quietly change behavior, What makes a test able to fail
The agent's rewrite (below) returns `[]` for any falsy input, then sorts a set comprehension of the cleaned tags. Running old and new code: | input | old | new | test | |---|---|---|---| | `"a,b"` | `[a,b]` | `[a,b]` | agent's: green | | `"b,A,a"` | `[b,a]` | `[a,b]` | pin: **RED** | | `None` | AttributeError | `[]` | pin: **RED** | Ask the agent to restore first-seen order and remove the `None` guard. Change the behaviour later, on purpose.
// Python
def parse_tags(raw):
    if not raw: return []
    return sorted({t.strip().lower()
                   for t in raw.split(",") if t.strip()})
Terms on this card
pin
To record a piece of current behaviour as a test's expected value, so that any change to it turns the test red.
None
Python's null value, meaning 'no object'.
AttributeError
Python exception raised when an attribute or method doesn't exist on an object, e.g. calling .split on None.
set comprehension
Python syntax {expr for x in items} that builds a set. It removes duplicates and keeps no meaningful order.
the agent
The AI coding system doing the work: a chat assistant, IDE agent or terminal agent.
Learn this step by step on Bytewise
Lesson goal: Write characterization tests that capture what existing code currently does before letting an agent refactor it. Use them to catch unintended behaviour changes that the agent's own new tests would miss. · the whole lesson