> ## Documentation Index
> Fetch the complete documentation index at: https://docs.tembo.io/llms.txt
> Use this file to discover all available pages before exploring further.

# Fix bugs

> Detect errors from Sentry, analyze the root cause, and open fix PRs automatically.

Tembo monitors your error tracking tools and automatically generates [pull requests](https://docs.tembo.io/features/pull-requests.md) to fix bugs as they happen in production.

## How it works

**1. Error detected**

Sentry captures an error in your application and sends a webhook to Tembo.

**2. Analysis**

Tembo retrieves the full error context (stack traces, breadcrumbs, environment details) and analyzes your codebase to understand the root cause.

**3. Fix generated**

A coding agent writes the fix in an isolated [sandbox](https://docs.tembo.io/features/sandbox/overview.md), runs tests, and opens a PR with the change and full context.

**4. Review and merge**

You review the PR and [mention Tembo](https://docs.tembo.io/features/mentioning-tembo.md) to iterate if needed. Merge when ready.

## Set up automatic bug fixes

### 1. Connect Sentry

Open **Settings > Integrations** and connect your Sentry account. Map your Sentry projects to the repositories where errors occur.

See the full [Sentry integration guide](https://docs.tembo.io/integrations/sentry.md) for details.

### 2. Create an agent

Go to **Agents** in your dashboard and create a new agent with a Sentry event trigger.

**Trigger**: `sentry.issue.created` or `sentry.issue.regression`
**[MCP Servers](https://docs.tembo.io/integrations/mcp.md)**: GitHub + Sentry

Example instructions:

```text theme={null}
When a new Sentry error is detected:
1. Retrieve the full stack trace and error context
2. Identify the root cause in the codebase
3. Write a fix and add tests
4. Open a PR with a clear description of what went wrong and how it's fixed
```

> [!TIP]
>
> Use the **Auto Fix Sentry Errors** template to automatically diagnose new errors, identify the root cause, and open a fix PR.

### 3. Fine-tune with rule files

Add [rule files](https://docs.tembo.io/features/rule-files.md) to your repo so the agent follows your coding standards, test patterns, and PR conventions when generating fixes.

## Best practices

* **Map projects accurately**: Connect [Sentry](https://docs.tembo.io/integrations/sentry.md) projects to the correct repos, especially for monorepos.
* **Enable rich context**: Turn on source maps, breadcrumbs, and custom tags in Sentry so the agent has more to work with.
* **Review before merging**: Always review the PR. [Mention Tembo](https://docs.tembo.io/features/mentioning-tembo.md) to refine the fix.
* **Test in staging first**: Validate fixes in a staging environment before merging to production.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.