Sub topic 2
The main risks: correctness, security, data, and licensing
This chapter assumes you know the pull request workflow, have done code review, have used an AI coding assistant, and know what a CI pipeline does. It covers the four risk areas that a team policy has to address. Later chapters turn each risk into rules.
Why risk comes first
A policy that does not name a risk cannot control it. Each rule in the rest of this tutorial exists because of one of the four risks below. If you can't say which risk a rule addresses, the rule is probably noise.
Correctness
AI assistants produce code that looks right more often than code that is right. The output is fluent and consistently formatted, so reviewers tend to trust it.
Common failures:
- Calls to functions or library options that do not exist.
- Code that handles the normal case and misses edge cases such as empty input, time zones, or concurrent access.
- Tests that pass because they repeat the implementation's assumptions.
- Changes that fix the stated problem but break behavior elsewhere.
Security
Generated code can reproduce insecure patterns found in its training data. Typical examples are string-built SQL queries, missing authorization checks, weak hashing, disabled certificate validation, and unsafe deserialization.
# Insecure pattern an assistant might produce
def find_user(db, name):
return db.execute(f"SELECT * FROM users WHERE name = '{name}'")
# Parameterized version
def find_user(db, name):
return db.execute("SELECT * FROM users WHERE name = ?", (name,))Agentic tools add a second concern. A tool that can run commands or install packages can be tricked by text in a file or web page, or can suggest a dependency that does not exist. Attackers register such invented package names so the install pulls in malicious code.
Data
Anything you paste into a tool, or let it read, may leave your control. That can include source code, credentials, customer records, and internal designs. The exposure depends on the tool's terms: whether prompts are stored, who can see them, and whether they are used for training.
Typical leaks:
- A developer pastes a stack trace that contains customer emails.
- An agent reads a
.envfile and sends it as context. - A proprietary algorithm is shared with a consumer chat tool that has no contract with your company.
Licensing and intellectual property
Assistants can output code that resembles open source code under licenses with conditions, such as attribution or copyleft terms. Ownership of generated code is also unsettled in some jurisdictions. Your legal team, not the engineering team, answers these questions. The policy's job is to route them to the right people.
How the risks differ
| Risk | How it appears | Who usually catches it | Main control |
|---|---|---|---|
| Correctness | Wrong behavior, missing edge cases | Tests, reviewers | Required tests and review |
| Security | Vulnerable code, unsafe dependencies | Scanners, reviewers | Security checks, path owners |
| Data | Sensitive input leaves the company | Often nobody, until later | Data rules and approved tools |
| Licensing | Code with unwanted obligations | Legal, license scanners | Tool terms, scanning |
Correctness and security show up in the diff, so review and CI can catch them. Data risk happens before any code exists, so only rules and tool configuration prevent it.
Exercise
A developer pastes a production error log containing customer email addresses into an unapproved chat tool and gets a fix. The fix passes all tests and review. Which risk was not caught, and why could review not catch it?
Show answer
The data risk. The leak happened when the log was pasted, before any code existed, so the pull request showed nothing wrong. Only data-sharing rules and approved tools can prevent it.
Exercise
Name two ways an AI-generated change can pass a quick read but still fail correctness.
Show answer
Examples: it calls a function or option that does not exist, it ignores edge cases such as empty input, or its tests only repeat the implementation's assumptions.