Skip to main content

Semantic Testing for LLMs - Test your AI outputs with semantic similarity validation

Project description

🧪 PromptEval

Semantic Testing for LLMs - Test your AI outputs with semantic similarity validation.

Version Python License

🚀 Quick Start

Installation

pip install prompteval-core

CLI Usage

# Run tests
prompteval run adapter.yml --tests tests.yml --api-key $PROMPTEVAL_API_KEY

# Validate YAML files
prompteval validate tests.yml

# Generate HTML report
prompteval report results.json --output report.html

# Check license/quota
prompteval licenses --api-key $PROMPTEVAL_API_KEY

Python SDK

from prompteval import PromptEval

# Initialize client
client = PromptEval(api_key="pe_xxxxx")

# Run tests from files
result = client.run_from_files(
    adapter_path="adapter.yml",
    tests_path="tests.yml"
)

# Check results
print(f"Success rate: {result.success_rate}%")
print(f"Passed: {result.total_passed}/{result.total_tests}")

if not result.success:
    for test in result.failed_tests:
        print(f"❌ {test.id_test}: {test.similarity:.1%} similarity")

📋 Configuration Files

Adapter YAML

Define your LLM endpoint configuration:

name: fitness-llm-api
description: Fitness LLM Testing

# Endpoint
endpoint:
  url: https://fitness-llm.com/v1/chat
  method: POST
  timeout: 10

# Request template
request:
  headers:
    Content-Type: application/json
  
  template:
    prompt: "{{PROMPT}}"
    type: "{{TYPE}}"
    max_tokens: 150

# Response extraction
response:
  type: json
  path: choices.0.message.content

# Validation
validation:
  ml_threshold: 0.75
  use_semantic: true

execution:
  parallel_limit: 10
  batch_delay: 0.3
  output_dir: ./output

Test Cases YAML

Define your test cases:

tests:
  - name: duration_basic
    id: FIT-001
    description: Pregunta sobre tiempo de entrenamiento
    prompt: "Ask about training duration"
    context:
      PROMPT: "Ask about training duration"
      TYPE: "duration"
    expected: "Desde cuando estas entrenando este ejercicio o rutina"
    variants:
      - "Hace cuanto tiempo empezaste con este entrenamiento"
      - "Cuanto tiempo llevas entrenando este ejercicio"
      - "Por favor, dime cuándo empezaste con este entrenamiento."
      - "Cuéntame, ¿desde cuándo entrenas así?"
    threshold: 0.70
    tags:
      - duration

🔧 SDK Reference

PromptEval Client

from prompteval import PromptEval

client = PromptEval(
    api_key="pe_xxxxx",           # Required
    base_url="https://...",       # Optional (default: production)
    timeout=300                   # Optional (default: 300s)
)

Running Tests

# From files
result = client.run_from_files("adapter.yml", "tests.yml")

# From dictionaries
result = client.run(
    adapter={"name": "test", "endpoint": {...}},
    tests=[{"id": "T1", "expected": "..."}]
)

# From raw YAML
result = client.run_from_yaml(yaml_string)

EvalResult Object

result.success          # bool - True if all tests passed
result.success_rate     # float - Percentage of passed tests
result.total_tests      # int - Total number of tests
result.total_passed     # int - Number of passed tests
result.total_failed     # int - Number of failed tests
result.total_errors     # int - Number of errors
result.duration_ms      # float - Total duration in milliseconds
result.test_results     # List[TestResult] - All test results
result.failed_tests     # List[TestResult] - Only failed tests
result.passed_tests     # List[TestResult] - Only passed tests

TestResult Object

test.id_test            # str - Test identifier
test.description        # str - Test description
test.passed             # bool - Whether test passed
test.expected           # str - Expected result
test.actual             # str - Actual result
test.similarity         # float - Semantic similarity (0-1)
test.threshold          # float - Required threshold
test.duration_ms        # float - Test duration
test.error              # str - Error message if any

Account Methods

# Get licenses
licenses = client.get_licenses()
for lic in licenses:
    print(f"{lic.plan}: {lic.tests_remaining} tests remaining")

# Get usage
usage = client.get_usage(license_id)
print(f"Tests this month: {usage['tests_this_month']}")

# Get API keys
keys = client.get_api_keys(license_id)

🔑 Environment Variables

# Set API key (recommended)
export PROMPTEVAL_API_KEY=pe_xxxxx

# Then use without --api-key flag
prompteval run adapter.yml --tests tests.yml

🎯 CI/CD Integration

GitHub Actions

name: LLM Tests

on: [push, pull_request]

jobs:
  test:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      
      - name: Set up Python
        uses: actions/setup-python@v5
        with:
          python-version: '3.11'
      
      - name: Install PromptEval
        run: pip install prompteval
      
      - name: Run Tests
        env:
          PROMPTEVAL_API_KEY: ${{ secrets.PROMPTEVAL_API_KEY }}
        run: |
          prompteval run adapter.yml --tests tests.yml --output results.json
          prompteval report results.json --output report.html
      
      - name: Upload Report
        uses: actions/upload-artifact@v4
        with:
          name: test-report
          path: report.html

📊 Semantic Validation

PromptEval uses sentence transformers to compute semantic similarity between expected and actual outputs. This allows flexible matching that understands meaning, not just exact text.

Example:

  • Expected: "The capital of France is Paris"
  • Actual: "Paris is the capital city of France"
  • Similarity: 94%

Threshold configuration:

  • 0.90+ - Very strict (nearly exact match)
  • 0.75-0.89 - Strict (same meaning, different words)
  • 0.60-0.74 - Moderate (similar concept)
  • <0.60 - Loose (related topic)

🔗 Links

📄 License

Copyright (c) 2026 PromptEval. All Rights Reserved.

This source code is proprietary and confidential. Unauthorized copying, distribution, or use is strictly prohibited.


Made with ❤️ by the PromptEval Team

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

prompteval_core-0.1.2.tar.gz (3.5 MB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

prompteval_core-0.1.2-py3-none-any.whl (4.2 MB view details)

Uploaded Python 3

File details

Details for the file prompteval_core-0.1.2.tar.gz.

File metadata

  • Download URL: prompteval_core-0.1.2.tar.gz
  • Upload date:
  • Size: 3.5 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.10

File hashes

Hashes for prompteval_core-0.1.2.tar.gz
Algorithm Hash digest
SHA256 36794e356a79190158f7d3fe60078c05dae4a11bf5d2b1d28ee46941dda7d363
MD5 162cff00acecf091f0e072266d978135
BLAKE2b-256 8e2bed6e703486117f6d263758af55fa79103e83f8feed65905bc34878b56949

See more details on using hashes here.

File details

Details for the file prompteval_core-0.1.2-py3-none-any.whl.

File metadata

File hashes

Hashes for prompteval_core-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 6fb27579b5992d37048e4ccf02759c94800d1391d0649101fd7643287b0a0778
MD5 8f20aa10a86d11f15859ea799c4ff9a4
BLAKE2b-256 7c11678dbdc85cbcfe61d5cdf9c4f9743c1965f707e9ab87e405674797cd3b11

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page