Sub topic 2
The main risks: correctness, security, data, and licensing
This chapter assumes you know the basic Git and pull request workflow, have taken part in code reviews, have used an AI coding assistant or chat tool, and know roughly what a CI pipeline does. A team policy only works if it names the specific risks it is meant to control. This chapter lists those risks, shows how each one appears in daily work, and points to the policy tool that answers it. Later chapters cover those tools in detail.
A working model of the risks
AI-assisted code carries four main risks:
- Correctness: the code does not do what the author needed.
- Security: the code works but opens a vulnerability.
- Data: information leaves the team through the tool, or the tool acts on data it should not touch.
- Licensing: the code or its origin creates a legal or ownership problem.
The first two risks live in the code itself. The data risk lives in the act of using the tool. The licensing risk lives in where the output came from. This difference matters because it decides which control fits. You can review code for correctness. You cannot review a leaked secret back out of a vendor's logs.
Correctness risk
AI tools produce code that looks plausible. Plausible is not the same as correct. Common failure patterns include:
- Invented APIs. The tool calls a function, flag, or package option that does not exist, or that exists only in a different version of the library.
- Wrong assumptions about your system. The tool cannot see your business rules, so it fills the gaps with a generic guess.
- Subtle logic errors. Off-by-one bounds, wrong time zone handling, and missed null cases pass a quick read.
- Tests that prove nothing. A tool asked to "add tests" may write tests that assert whatever the code currently does, bugs included.
- Confident explanations. The tool describes its own code fluently, which makes a reviewer less likely to doubt it.
A short example shows how a plausible bug looks. Suppose a tool writes this function to compute a discount:
def apply_discount(price_cents: int, percent: int) -> int:
"""Return the price after applying a percentage discount."""
return price_cents - price_cents * percent / 100The code reads well, and for apply_discount(1000, 10) it returns 900.0. Two problems remain. The return type is declared int, but the division produces a float. Money would also be rounded in whatever way a float conversion happens to choose. A corrected version makes the rounding rule explicit:
def apply_discount(price_cents: int, percent: int) -> int:
"""Return the price after applying a percentage discount, rounded down."""
if not 0 <= percent <= 100:
raise ValueError("percent must be between 0 and 100")
discount = price_cents * percent // 100
return price_cents - discountA test that pins the behavior catches the difference:
def test_apply_discount_rounds_down_and_returns_int():
assert apply_discount(1000, 10) == 900
assert isinstance(apply_discount(999, 10), int)
assert apply_discount(999, 10) == 900Here the rounding rule (the discount is rounded down, so the price is rounded up) is a business decision. The tool cannot know it. A person has to decide it, and the policy has to make sure a person does.
The policy answer to correctness is author accountability, review that checks behavior, and tests that run on every change. A required CI job runs the same tests for every pull request, whoever wrote the code.
Security risk
Security problems are a special kind of correctness problem. The code does what it was asked to do, but it also does something an attacker can use. Typical patterns:
- Injection flaws. The tool builds a SQL query or shell command by joining strings with user input.
- Weak or outdated cryptography. The tool picks an old hash function or a fixed initialization value because it appears often in training material.
- Missing authorization checks. The endpoint authenticates the user but never checks whether that user may see the record.
- Hard-coded secrets. The tool copies a placeholder key into the code, and a developer replaces it with a real key to make the demo work.
- Risky dependencies. The tool suggests a package. Some suggested package names do not exist, and an attacker can register such a name and publish malicious code under it. This is sometimes called a "slopsquatting" attack.
- Over-trusting input. The tool skips validation at the boundary where outside data enters.
Here is the injection pattern in a form a reviewer can learn to spot:
import sqlite3
def find_user(conn: sqlite3.Connection, name: str):
# Unsafe: user input is placed directly into the SQL text.
query = f"SELECT id, name FROM users WHERE name = '{name}'"
return conn.execute(query).fetchall()
def find_user_safe(conn: sqlite3.Connection, name: str):
# Safe: the driver passes the value separately from the SQL text.
return conn.execute(
"SELECT id, name FROM users WHERE name = ?", (name,)
).fetchall()Security risk grows with speed. A developer who generates 400 lines in a minute may not read 400 lines in a minute. The policy answer is to route sensitive paths to named reviewers with a CODEOWNERS file, to run security scanners in CI, and to restrict where AI-generated code is allowed at all (for example, a team may mark cryptography code as restricted).
Data risk
The data risk is different in kind. It does not depend on whether the output is good. It depends on what you give the tool and what the tool is allowed to do.
There are two directions:
- Data going out. A developer pastes a stack trace that contains a customer email, a config file that contains an API key, or a block of proprietary source code into a hosted tool. That text now sits on a third party's systems. Depending on the vendor's terms and the plan you use, it may be retained, reviewed by staff, or used to train future models.
- Data reached by the tool. An agentic tool that runs commands or reads files can open an
.envfile, read a database dump in the working directory, or send file contents to a remote service as part of a task.
The same prompt can be safe on one plan and unsafe on another. A tool with a business agreement that forbids training on your inputs and limits retention is a different risk from a free consumer account. This is why data rules and tool approval are linked in the policy. The team approves specific tools and plans, then says which data classes may go to which tool.
A simple classification gives people something quick to apply:
| Data class | Examples | Typical rule |
|---|---|---|
| Public | Open-source code, public docs | May be shared with any approved tool |
| Internal | Non-sensitive source code, internal design notes | Approved tools on business plans only |
| Confidential | Customer data, credentials, unreleased security fixes | Never shared with external AI tools |
Your team may draw the lines differently. The value of the table is that a developer can decide in seconds without asking someone.
Secrets deserve special mention. Once a secret has been sent to an outside service, deleting your local copy does not undo the exposure. The standard response is to rotate the secret, meaning to revoke it and issue a new one.
Licensing and ownership risk
Licensing questions are the least settled of the four. Three issues come up:
- Reproduced code. A model can output text that closely matches code it saw in training, including code under licenses with obligations such as attribution or "copyleft" terms (rules that require derived work to be shared under the same license). If that text lands in your product without notice, you may take on those obligations without knowing it.
- Ownership of the output. Whether AI-generated material can be protected by copyright, and who holds the rights, varies by country and is still being decided in courts and legislatures. Vendor terms add another layer.
- Inbound dependencies. AI-suggested packages carry their own licenses, which may conflict with how you distribute your software.
This chapter does not give legal advice, and your policy should not try to settle these questions alone. The practical position is to involve legal counsel when drafting, to prefer tools that offer duplicate-code filters or indemnification terms where the business needs that, and to run a license scanner on dependencies in CI. Some tools can flag output that matches public code. Whether to require that setting is a decision for the policy.
How the risks combine
The risks are not independent. One careless action can trigger several at once.
| Scenario | Correctness | Security | Data | Licensing |
|---|---|---|---|---|
| Developer pastes production logs into a chat tool and asks for a fix | The fix may not match your system | The logs may reveal weaknesses | Customer data leaves the company | None directly |
| Agent installs a suggested package and runs its install script | The package may not behave as expected | Install script can run attacker code | Script may read local files | The package may carry an incompatible license |
| Tool rewrites a login function in one pass | Edge cases may be lost | Authorization checks may be dropped | None directly | Output may mirror public code |
Reading the table by row shows why policies cannot rely on one control. Reading it by column shows which controls to build: tests and review for correctness, scanners and code owners for security, data rules and tool approval for data, and license checks for licensing.
Common errors when assessing the risks
- Treating the risk as only "bad code." Teams that look only at output quality miss the data risk, which can occur before any code is generated.
- Assuming a tool's good reputation settles the data question. The plan and settings decide retention and training use, not the brand.
- Writing rules that cannot be checked. "Don't use AI for anything risky" gives no one a way to decide. Chapters ahead turn each risk into a rule people can follow and, where possible, a check a machine can enforce.
- Ignoring the benefit side. A policy that bans everything pushes use into unapproved personal accounts, which raises the data risk. Controlled use is safer than hidden use.
Summary of risks and controls
| Risk | Main failure | First-line control | Where it is covered later |
|---|---|---|---|
| Correctness | Plausible but wrong code | Author accountability, tests in CI | Accountability, review, guardrails |
| Security | Exploitable code or dependency | Code owners, scanners, restricted paths | Acceptable use, guardrails |
| Data | Secrets or customer data leave the team | Data classes, approved tools | Data confidentiality, tool approval |
| Licensing | Unknown obligations or ownership | Legal input, license scanning, tool terms | Licensing, tool approval |
Exercise
A developer asks an AI chat tool on a free personal account to "fix this failing query," and pastes in the query plus ten rows of real customer records from a production table. The tool returns a fix built by string concatenation. Which of the four risks are present, and name one control for each.
Show answer
Data risk: customer records were sent to an unapproved tool and plan. Controls: a data-classification rule that bans confidential data in external tools, and an approved-tool list that excludes personal accounts. Security risk: string concatenation in a query is an injection flaw. Controls: parameterized queries enforced in review, plus a security scanner in CI. Correctness risk is also present because the fix was written without knowledge of the real schema or business rules. Controls: author accountability and a test that runs in CI. Licensing risk is low here, so no special control is needed beyond normal dependency scanning.
Exercise
Why can code review not serve as the only control for the data risk?
Show answer
The data risk occurs when the developer sends the prompt, before any code reaches a pull request. By the time a reviewer sees the change, the data has already left. Controls must act earlier: clear rules on what may be shared, approved tools with suitable retention terms, and tool configuration that limits what an agent can read.