Skip to main content

Testing Strategies

Testing AI prompts is essential for ensuring consistent, high-quality outputs. This guide covers comprehensive testing strategies for Claro prompts, from development to production.

Why Test Prompts?

AI prompts require testing because:
  • Variability - LLMs can produce different outputs for the same input
  • Edge Cases - Unexpected inputs can lead to poor responses
  • Version Changes - Updates may introduce unintended behavior
  • Quality Assurance - Ensure prompts meet business requirements
Unlike traditional code, AI prompts can’t guarantee deterministic outputs. Testing focuses on quality patterns and acceptable ranges rather than exact matches.

Testing Before Deployment

Manual Testing in Dashboard

The fastest way to test prompts before publishing:
1

Create Draft Version

In the Bayt OS dashboard, create a new draft or edit an existing prompt
2

Use Preview Mode

Test the prompt directly in the editor:
  • Enter sample inputs
  • Review generated outputs
  • Test edge cases
  • Verify tone and style
3

Iterate and Refine

Make adjustments based on test results, then re-test
4

Publish When Ready

Once satisfied with test results, publish the version

Test Input Categories

Test prompts with diverse input types:
Expected Use Cases
  • Typical user queries
  • Well-formed inputs
  • Common scenarios
  • Standard requests
These should produce the best responses.

Unit Testing with Mocked Responses

Testing Integration Code

Test your application’s integration with Claro independently:

Testing LLM Integration

Test the complete flow with mocked LLM responses:

Integration Testing

Testing with Real API Calls

Create integration tests that call the actual Claro API:

Running Integration Tests

Separate integration tests from unit tests:

A/B Testing Approaches

Comparing Prompt Versions

Test multiple versions side-by-side:

Production A/B Testing

Gradually roll out new versions in production:

Tracking A/B Test Results

Log metrics for each version:

CI/CD Integration

GitHub Actions Example

Automate testing in your CI pipeline:

Pre-commit Hooks

Test before committing:

Best Practices

Don’t just test with synthetic data:
  • Collect actual user queries from logs
  • Test with real support tickets
  • Use production-like scenarios
  • Include edge cases from real usage
Create a test suite that runs automatically:
Track metrics across versions:
  • Response time
  • Token usage
  • User satisfaction (thumbs up/down)
  • Error rates
  • Escalation rates (for support prompts)
Compare metrics between versions to identify improvements or regressions.
Validate that prompts follow their instructions:
Always pin to specific versions in tests:
Test how your application handles errors:

Testing Tools and Frameworks

pytest

Python testing framework
  • Powerful fixtures
  • Parametrized tests
  • Great mocking support

pytest-mock

Mocking library
  • Easy API mocking
  • Patch functions
  • Verify call counts

pytest-cov

Coverage reporting
  • Track test coverage
  • Identify untested code
  • CI integration

Locust

Load testing
  • Test at scale
  • Simulate concurrent users
  • Performance metrics

Load Testing Example

Test prompt performance under load:
Run load tests:

Troubleshooting Tests

Common causes:
  • Environment variables not set in CI
  • Different Python versions
  • Timezone or locale differences
Solution: Ensure CI environment matches local environment. Set all required secrets in CI.
Common causes:
  • Network timeouts
  • Rate limiting
  • Non-deterministic LLM outputs
Solution: Add retries for integration tests:
Common causes:
  • Patching wrong location
  • Import order issues
  • Mock not properly configured
Solution: Patch where the function is used, not where it’s defined:

Next Steps

Error Handling

Learn comprehensive error handling for robust tests

Performance Guide

Optimize prompt fetching and caching

Security

Secure API keys in test environments

Advanced Patterns

Production-ready integration patterns