# AI-Assisted Error Analysis

sfp provides intelligent AI-assisted error analysis to help developers quickly understand and resolve validation failures. When enabled through the `errorAnalysis` configuration in `ai-assist.yaml`, the system automatically analyzes error patterns and provides actionable insights.

{% hint style="warning" %}
AI-assisted error analysis requires:

1. The `errorAnalysis.enabled` flag set to `true` in `config/ai-assist.yaml`
2. A configured LLM provider (OpenAI, Anthropic, etc.)

LLM providers are configured through your sfp server integrations.
{% endhint %}

## Quick Setup

1. Create `config/ai-assist.yaml` in your project root:

   ```bash
   mkdir -p config
   touch config/ai-assist.yaml
   ```
2. Add the minimal configuration:

   ```yaml
   # config/ai-assist.yaml
   errorAnalysis:
     enabled: true
   ```
3. Set your LLM provider credentials (e.g., in CI/CD secrets)

That's it! AI error analysis will automatically activate during validation failures.

## How It Works

### 1. Change Significance Analysis

Before triggering AI analysis, sfp evaluates if changes are significant enough to warrant review:

* **Metadata Type Detection**: Uses Salesforce ComponentSet for accurate identification
* **Smart Thresholds**: Different thresholds per file type (Apex: 3 lines, Flows: 1 line, LWC: 10 lines)
* **Automatic Exclusions**: Skips non-critical metadata (CustomLabels, StaticResources, Translations)

### 2. Error Analysis

When validation fails and changes are significant, AI provides:

* **Root Cause Analysis**: Understanding why the error occurred
* **Quick Fix Suggestions**: Immediate actions to resolve issues
* **Related Components**: Other files that might be involved
* **Documentation Links**: References to relevant Salesforce docs

## Configuration

Configure AI assistance through `config/ai-assist.yaml`:

```yaml
# config/ai-assist.yaml

# Error Analysis Configuration
errorAnalysis:
  enabled: true                    # Enable/disable AI error analysis
  provider: openai                 # AI provider (openai, anthropic, etc.)
  model: gpt-4                     # Model to use
  timeout: 180000                  # Timeout in ms (default: 3 minutes)
  maxSuggestedFixes: 5            # Max number of fix suggestions

# Change Significance Configuration
architecture:
  changeSignificance:
    # Metadata types to exclude from analysis
    excludedMetadataTypes:
      - CustomLabels
      - StaticResource
      - CustomTab

    # Thresholds for triggering analysis
    fileTypeThresholds:
      apex:
        lines: 3    # Very strict for Apex
        files: 1
      flows:
        lines: 1    # Any flow change
        files: 1
      lwc:
        lines: 10   # More lenient for UI
        files: 2
```

## Usage

AI error analysis is **automatically enabled** when:

1. A `config/ai-assist.yaml` file exists in your project
2. The `errorAnalysis.enabled` flag is set to `true`
3. Valid LLM provider credentials are available

No additional CLI flags are required - sfp automatically detects and uses the configuration.

<figure><img src="/files/8rD6iWp1IDDS8UU9MQVv" alt=""><figcaption></figcaption></figure>


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.flxbl.io/flxbl/sfp/validating-a-change/ai-assisted-error-analysis.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
