Skip to main content

Overview

This example demonstrates various error handling patterns in SemanticTest, including:
  • Detecting validation failures
  • Handling API errors
  • Retry logic with Loop blocks
  • Graceful degradation

Testing Error Scenarios

test.json

Pattern 1: Validate Then Assert

Always validate data before making assertions:

Pattern 2: Graceful Degradation

Test that your system handles missing data gracefully:

Pattern 3: Retry Logic

Retry failed operations with exponential backoff:
This will retry the API call up to 3 times if the status is not 200.

Pattern 4: Expected Failures

Test that your system correctly rejects invalid input:

Pattern 5: Multiple Validation Layers

Implement defense in depth:

Pattern 6: Error Messages

Validate error messages are helpful:

Pattern 7: Timeout Handling

Test timeout scenarios:

Real-World Example

Complete error handling for API integration:

Best Practices

Use ValidateContent or ValidateTools before making assertions on data structure.
Write tests for both happy paths and error scenarios.
Assert on specific error codes, not just “something failed”.
Use Loop blocks to retry flaky operations automatically.
Ensure error messages are helpful and don’t leak sensitive info.

Next Steps

Loop Block

Learn about retry logic with Loop

ValidateContent

Content validation reference

Assertions

All assertion operators

Calendar Agent

Complex agent testing example