---
title: "AI code security"
description: "How Baz reviews code that calls language models, runs agents, or configures MCP servers against the OWASP Top 10 for LLM Applications."
canonical: "https://baz.ai/docs/security/ai-code-security"
---

# AI code security

How Baz reviews code that calls language models, runs agents, or configures MCP servers against the OWASP Top 10 for LLM Applications.

Code that calls a language model has a different threat model from ordinary application code. The model reads untrusted text (user messages, retrieved documents, web pages, PR bodies, tool results), and hidden instructions in that text can change what it does. When a pull request touches this kind of code, Baz adds checks based on the OWASP Top 10 for LLM Applications (2025) to the **Basic Security Patterns** review and tags each finding with the matching LLM IDs.

## When the LLM checks run

The checks are added when Basic Security Patterns is enabled and a changed file:

- Imports or calls a model provider SDK, gateway, agent framework, or MCP library (for example OpenAI, Anthropic, Bedrock, Gemini, LangChain, LangGraph, LlamaIndex, CrewAI, the Vercel AI SDK, or an MCP server SDK).
- Calls a model API directly over HTTP.
- Belongs to a package whose nearest manifest depends on one of those libraries.
- Is an agent configuration file: `mcp.json`, `.mcp.json`, `claude_desktop_config.json`, or `.claude/settings.json`.
- Is a GitHub Actions workflow under `.github/workflows/` that runs a coding agent or an LLM library.

Changes with none of these signals get the standard Basic Security Patterns review only.

## How Baz judges LLM code

Two rules shape every LLM finding:

- **Model output is attacker-controlled.** The model's reply text, the arguments it passes to tools, the parameters of any function registered as a tool, and output handed from one agent to another are treated exactly like a raw HTTP request body.
- **Asking a model to check something is not a security control.** A prompt that says "refuse if...", an LLM-based query checker, or a guardrail classifier can be tricked, so Baz does not count it as protection.

Prompt injection is not reported by itself. Baz reports it when untrusted text reaches the system or developer message, or when the same agent can also run code, change data, or send data out.

## OWASP Top 10 for LLM Applications

This is the standard list of the ten biggest risks in apps that use language models, from **LLM01 Prompt injection** to **LLM10 Unbounded consumption**. Baz checks the code for each risk it can see there, such as model output run as a shell command, secrets placed in a prompt, or a powerful tool with no approval step. It never flags **LLM09 Misinformation**, because that is how a model behaves, not something written in your code.

Each LLM finding starts with its OWASP IDs and names, for example "LLM05 Improper Output Handling, LLM06 Excessive Agency". Baz turns the IDs into badges on the comment.

## The patterns Baz checks

Baz looks for three kinds of trouble. Untrusted text or model output reaches something dangerous, like a shell, a database query, a URL the model picked, or rendered HTML. A safety check around the AI is missing, like an approval step on a tool that changes data or a per-tenant filter on retrieval. Or the AI setup itself is unsafe, like disabled safety flags, secrets in prompts, or an untrusted MCP server.

Before posting, Baz traces the untrusted input to the dangerous action, or confirms the safety check is really missing, so you get findings you can act on rather than generic AI warnings.

### Example

A tool that fetches any URL the model chooses is a server-side request forgery path, because anyone who can put text in front of the model can choose the URL:

```python title="tools.py"
@tool
def fetch(url: str) -> str:
    return requests.get(url).text
```

Baz flags this as LLM06 and LLM05 unless the code restricts the host with an allowlist, blocks private IPs after DNS resolution, and applies the same check to redirects.

## What Baz does not flag

- Tests, evaluation harnesses, red-team datasets, notebooks, examples, and docs.
- Fixed prompts written by developers and filled only with trusted values.
- Single-user local CLIs and dev agents with no other customer's data.
- Code run inside a real sandbox (for example E2B, Modal, or a Docker, gVisor, or Firecracker executor).
- A missing moderation call, guardrail library, or "prompt-injection detector". These are product choices.
- Anything that only says "the model might make things up or be tricked" without a concrete dangerous action or missing check.
- Package version pins. The [dependency checks](/docs/security/supply-chain) cover those.

Behavior that cannot be seen in a diff, such as jailbreak resistance, bias, training-time poisoning, or model theft, is never flagged.

## Related

<CardGroup cols={2}>
  <Card title="Basic Security Patterns" href="/docs/agents/build/basic-security-patterns" icon="shield-check">
    Configure the agent that runs these checks.
  </Card>
  <Card title="Security overview" href="/docs/security" icon="shield">
    How the security layers fit together.
  </Card>
  <Card title="Prioritization" href="/docs/security/prioritization" icon="gauge">
    Severity and OWASP classification for every finding.
  </Card>
  <Card title="Skills and instructions" href="/docs/brain/skills-and-instructions" icon="file-code">
    Put your own AI security rules where Baz enforces them.
  </Card>
</CardGroup>
