link,[object Object]
Skip to content

AI Troubleshooting Guide ​

Common AI Issues ​

1. Authentication Errors ​

Problem: "Invalid authentication" or 401 errors ​

Symptoms:

  • AI analysis fails with 401 status
  • "Invalid authentication" error message
  • Edge Function returns 401

Solutions:

  1. Check user login status:

    javascript
    // In browser console
    console.log('Session:', session);
    console.log('Access token:', session?.access_token);
  2. Verify JWT token:

    • Ensure user is logged in
    • Check if token has expired
    • Try logging out and back in
  3. Check Edge Function authentication:

    bash
    # Check Edge Function logs
    supabase functions logs analyze-project --project-ref nujcbrbtejvhuajfwgeo

Prevention:

  • Implement token refresh logic
  • Add session validation before AI calls
  • Monitor token expiration

2. Rate Limiting ​

Problem: "Service is currently overloaded. Please try again in 10 minutes." ​

Symptoms:

  • 429 status code from Mistral API
  • "Service tier capacity exceeded" error
  • AI analysis fails with rate limit message

Solutions:

  1. Wait and retry:

    • Wait 10 minutes before retrying
    • Implement exponential backoff
    • Show user-friendly message
  2. Switch models:

    typescript
    // In Edge Function
    const model = 'mistral-small-latest'; // Instead of mistral-large-latest
  3. Optimize prompts:

    • Reduce max_tokens
    • Simplify prompt structure
    • Use more concise instructions

Prevention:

  • Monitor API usage
  • Implement request queuing
  • Consider upgrading Mistral plan

3. JSON Parsing Errors ​

Problem: "Failed to parse AI analysis" ​

Symptoms:

  • JSON.parse() errors in Edge Function
  • Malformed JSON from Mistral API
  • Truncated or incomplete responses

Solutions:

  1. Check Edge Function logs:

    bash
    supabase functions logs analyze-project --project-ref nujcbrbtejvhuajfwgeo
  2. Verify Mistral API response:

    • Check if response is complete
    • Look for truncation issues
    • Verify JSON structure
  3. Use error recovery:

    • The system automatically attempts recovery
    • Falls back to minimal valid response
    • Logs detailed error information

Prevention:

  • Optimize prompts for consistency
  • Reduce max_tokens to avoid truncation
  • Implement robust error handling

4. Field Population Issues ​

Problem: Fields not populated correctly ​

Symptoms:

  • Some form fields remain empty
  • Category not selected
  • Structured descriptions not populated
  • Price not showing

Solutions:

  1. Check AI response mapping:

    javascript
    // In browser console
    console.log('AI Data received:', aiData);
    console.log('Mapped data:', mappedData);
  2. Verify field mapping:

    • Check N8NAIProjectAnalyzer.tsx mapping
    • Verify CreateListingContent.tsx handling
    • Ensure correct field names
  3. Check category normalization:

    • Verify category slugs from database
    • Check normalization logic
    • Ensure valid category selection

Prevention:

  • Test with various project types
  • Validate all field mappings
  • Add comprehensive logging

5. Network and Timeout Issues ​

Problem: Request timeouts or network errors ​

Symptoms:

  • "Failed to fetch" errors
  • Request timeouts
  • Network connectivity issues

Solutions:

  1. Check network connectivity:

    • Verify internet connection
    • Test with different URLs
    • Check firewall settings
  2. Increase timeout:

    typescript
    // In Edge Function
    const controller = new AbortController();
    const timeoutId = setTimeout(() => controller.abort(), 120000); // 2 minutes
  3. Implement retry logic:

    • Add retry mechanism
    • Exponential backoff
    • User notification

Prevention:

  • Set appropriate timeouts
  • Implement retry logic
  • Monitor network performance

Debugging Steps ​

1. Check Frontend Logs ​

javascript
// Open browser console and check:
console.log('Session:', session);
console.log('AI Data:', aiData);
console.log('Form Data:', formData);

2. Check Edge Function Logs ​

bash
# Check recent logs
supabase functions logs analyze-project --project-ref nujcbrbtejvhuajfwgeo

# Check specific time range
supabase functions logs analyze-project --project-ref nujcbrbtejvhuajfwgeo --since 1h

3. Test Edge Function Directly ​

bash
# Test with curl
curl -X POST https://nujcbrbtejvhuajfwgeo.supabase.co/functions/v1/analyze-project \
  -H 'Content-Type: application/json' \
  -H 'Authorization: Bearer YOUR_SUPABASE_ANON_KEY' \
  -d '{"url":"https://example.com"}'

4. Check Supabase Secrets ​

bash
# List all secrets
supabase secrets list --project-ref nujcbrbtejvhuajfwgeo

# Check specific secret
supabase secrets get MISTRAL_API_KEY --project-ref nujcbrbtejvhuajfwgeo

Monitoring and Alerts ​

1. Set Up Monitoring ​

  • Monitor Edge Function execution times
  • Track API success/failure rates
  • Monitor Mistral API usage and costs

2. Implement Alerts ​

  • Alert on high error rates
  • Monitor rate limit usage
  • Track unusual response patterns

3. Log Analysis ​

  • Regular log review
  • Error pattern identification
  • Performance trend analysis

Best Practices ​

1. Error Handling ​

  • Always implement try-catch blocks
  • Provide user-friendly error messages
  • Log detailed error information
  • Implement graceful degradation

2. Performance ​

  • Optimize prompts for token efficiency
  • Implement caching where appropriate
  • Monitor response times
  • Set appropriate timeouts

3. Security ​

  • Never expose API keys in frontend
  • Use Supabase secrets for sensitive data
  • Implement proper authentication
  • Monitor for suspicious activity

Getting Help ​

1. Check Documentation ​

2. Review Logs ​

  • Check Edge Function logs
  • Review browser console
  • Analyze error patterns

3. Test Scenarios ​

  • Test with different project types
  • Verify with various URLs
  • Check edge cases

4. Contact Support ​

  • Provide detailed error logs
  • Include reproduction steps
  • Share relevant configuration