Best practices for writing AI extensions

The Montoya API enables you to integrate AI-powered functionality into your Burp Suite extensions. Follow these best practices to ensure your extension is efficient and user-friendly.

Note

Declare AI support and check availability

For your extension to use AI features, you must:

This ensures that the Use AI checkbox appears for users and that your extension handles scenarios where AI features are unavailable.

More information

For more information, see Developing AI features in extensions - Checking AI availability.

Mitigate prompt injection attacks

Treat raw output from AI models as untrusted. Escape any AI-generated content before presenting it to users. Make sure that you use proper HTML encoding to neutralize potential threats.

Optimize AI requests for efficiency and security

To ensure AI interactions are both efficient and secure, it's important to control what data is sent, how it's formatted, and when requests are made.

To optimize requests effectively:

Use effective prompts

A well-structured prompt ensures that the AI provides relevant and high-quality responses. We recommend that you:

More information

For more information, see Developing AI features in extensions - Sending prompts and handling responses.

Use lower temperatures for better accuracy

The temperature setting controls the balance between determinism and creativity in AI responses. In general, lower values produce focused and accurate results. The default is 0.5. Conversely, higher values may cause the AI to go off on tangents, potentially making security-related responses unreliable.

More information

For more information, see Developing AI features in extensions - Setting the temperature.

Handle exceptions gracefully

AI calls can fail for various reasons, such as the user not having enough credits or service downtime. Handle exceptions gracefully to ensure your extension is able to continue functioning as expected for your users.

The PromptException class represents errors that may occur during AI prompt execution. It is thrown if there is an issue with the AI request. Wrap AI calls in a try-catch block to handle errors appropriately.

More information

For more information, see Developing AI features in extensions - Handling exceptions.

Use an executor service where necessary to avoid blocking threads

AI requests can take longer than typical Burp API calls. Running them in the Swing Event Dispatch Thread can cause Burp to appear unresponsive, as the whole GUI must wait until the slow operation completes.

To keep Burp's UI responsive, execute AI calls asynchronously using an executor service. This prevents long-running operations from locking the Swing thread.