Test every feature from a fresh install. No repo cloning needed.
Requirements: Python 3.10+, an OpenAI API key Estimated cost: ~$0.50–$2.00 depending on K and number of questions
mkdir trustgate-test && cd trustgate-test
python3 -m venv .venv
source .venv/bin/activate
pip install theaios-trustgate
export LLM_API_KEY="sk-your-key-here" # any OpenAI-compatible API keymkdir trustgate-test; cd trustgate-test
python -m venv .venv
.venv\Scripts\Activate.ps1
pip install theaios-trustgate
$env:LLM_API_KEY="sk-your-key-here" # any OpenAI-compatible API keyCreate a config file and test questions. On macOS/Linux use the commands below. On Windows, create these two files manually or use the Python script at the end of this section.
cat > trustgate.yaml << 'EOF'
# Works with any OpenAI-compatible API (OpenAI, Together, Ollama, LiteLLM, etc.)
# Auth option 1: env var (standard Bearer token)
# api_key_env: "LLM_API_KEY"
# Auth option 2: custom headers (LiteLLM, Azure, etc.)
# headers:
# API-Key: "your-key-here"
endpoint:
url: "https://api.openai.com/v1/chat/completions"
model: "gpt-4.1-mini"
api_key_env: "LLM_API_KEY"
canonicalization:
type: "llm"
judge_endpoint:
url: "https://api.openai.com/v1/chat/completions"
model: "gpt-4.1-nano"
api_key_env: "LLM_API_KEY"
sampling:
k_fixed: 5
sequential_stopping: true
calibration:
alpha_values: [0.01, 0.05, 0.10, 0.20]
n_cal: 25
n_test: 25
thresholds:
pass: 0.80
weak: 0.50
questions:
file: "questions.csv"
EOF
cat > questions.csv << 'EOF'
id,question,acceptable_answers
q01,What is the capital of France?,Paris
q02,What is 2+2?,4
q03,Who painted the Mona Lisa?,Da Vinci
q04,What is the chemical symbol for gold?,Au
q05,How many continents are there?,7
q06,What is the largest ocean?,Pacific
q07,Who wrote Romeo and Juliet?,Shakespeare
q08,What is the boiling point of water in Celsius?,100
q09,What is the square root of 144?,12
q10,Which planet is the largest?,Jupiter
q11,What is the capital of Japan?,Tokyo
q12,Who developed the theory of relativity?,Einstein
q13,What is the chemical formula for water?,H2O
q14,What is the tallest mountain in the world?,Everest
q15,How many minutes are in an hour?,60
q16,What is the smallest prime number?,2
q17,What is the longest river in the world?,Nile
q18,Which element has atomic number 1?,Hydrogen
q19,What is the capital of Australia?,Canberra
q20,Who discovered penicillin?,Fleming
q21,What is the speed of light approximately?,300000 km/s
q22,What is the capital of Germany?,Berlin
q23,How many bones in the adult human body?,206
q24,What is the largest mammal?,Blue whale
q25,Who invented the telephone?,Bell
q26,What is the pH of pure water?,7
q27,What is the capital of Brazil?,Brasilia
q28,How many planets in our solar system?,8
q29,What is the hardest natural substance?,Diamond
q30,Who painted Starry Night?,Van Gogh
q31,What is the capital of Canada?,Ottawa
q32,What is the freezing point of water in Celsius?,0
q33,How many legs does a spider have?,8
q34,What is the chemical symbol for sodium?,Na
q35,Who was the first person to walk on the moon?,Armstrong
q36,What is the capital of Italy?,Rome
q37,What is the cube root of 27?,3
q38,Who wrote Don Quixote?,Cervantes
q39,What is the unit of electrical resistance?,Ohm
q40,What is the capital of India?,New Delhi
q41,How many strings does a standard guitar have?,6
q42,What is the largest desert in the world?,Antarctic
q43,What is the capital of Mexico?,Mexico City
q44,Who composed the Four Seasons?,Vivaldi
q45,What is the smallest continent?,Australia
q46,What is the capital of Egypt?,Cairo
q47,What is the atomic number of carbon?,6
q48,Which is the hottest planet?,Venus
q49,How many colors are in a rainbow?,7
q50,What is the capital of Spain?,Madrid
EOFWindows alternative — run this Python script to create both files:
python -c "
config = '''endpoint:
url: https://api.openai.com/v1/chat/completions
model: gpt-4.1-mini
api_key_env: LLM_API_KEY
canonicalization:
type: llm
judge_endpoint:
url: https://api.openai.com/v1/chat/completions
model: gpt-4.1-nano
api_key_env: LLM_API_KEY
sampling:
k_fixed: 5
sequential_stopping: true
calibration:
alpha_values: [0.01, 0.05, 0.10, 0.20]
n_cal: 25
n_test: 25
thresholds:
pass: 0.80
weak: 0.50
questions:
file: questions.csv
'''
open('trustgate.yaml','w').write(config)
questions = 'id,question,acceptable_answers\n'
qs = [('q01','What is the capital of France?','Paris'),('q02','What is 2+2?','4'),('q03','Who painted the Mona Lisa?','Da Vinci'),('q04','What is the chemical symbol for gold?','Au'),('q05','How many continents are there?','7'),('q06','What is the largest ocean?','Pacific'),('q07','Who wrote Romeo and Juliet?','Shakespeare'),('q08','What is the boiling point of water in Celsius?','100'),('q09','What is the square root of 144?','12'),('q10','Which planet is the largest?','Jupiter'),('q11','What is the capital of Japan?','Tokyo'),('q12','Who developed the theory of relativity?','Einstein'),('q13','What is the chemical formula for water?','H2O'),('q14','What is the tallest mountain in the world?','Everest'),('q15','How many minutes are in an hour?','60'),('q16','What is the smallest prime number?','2'),('q17','What is the longest river in the world?','Nile'),('q18','Which element has atomic number 1?','Hydrogen'),('q19','What is the capital of Australia?','Canberra'),('q20','Who discovered penicillin?','Fleming'),('q21','What is the speed of light approximately?','300000 km/s'),('q22','What is the capital of Germany?','Berlin'),('q23','How many bones in the adult human body?','206'),('q24','What is the largest mammal?','Blue whale'),('q25','Who invented the telephone?','Bell'),('q26','What is the pH of pure water?','7'),('q27','What is the capital of Brazil?','Brasilia'),('q28','How many planets in our solar system?','8'),('q29','What is the hardest natural substance?','Diamond'),('q30','Who painted Starry Night?','Van Gogh'),('q31','What is the capital of Canada?','Ottawa'),('q32','What is the freezing point of water in Celsius?','0'),('q33','How many legs does a spider have?','8'),('q34','What is the chemical symbol for sodium?','Na'),('q35','Who was the first person to walk on the moon?','Armstrong'),('q36','What is the capital of Italy?','Rome'),('q37','What is the cube root of 27?','3'),('q38','Who wrote Don Quixote?','Cervantes'),('q39','What is the unit of electrical resistance?','Ohm'),('q40','What is the capital of India?','New Delhi'),('q41','How many strings does a standard guitar have?','6'),('q42','What is the largest desert in the world?','Antarctic'),('q43','What is the capital of Mexico?','Mexico City'),('q44','Who composed the Four Seasons?','Vivaldi'),('q45','What is the smallest continent?','Australia'),('q46','What is the capital of Egypt?','Cairo'),('q47','What is the atomic number of carbon?','6'),('q48','Which is the hottest planet?','Venus'),('q49','How many colors are in a rainbow?','7'),('q50','What is the capital of Spain?','Madrid')]
for qid,q,a in qs: questions+=f'{qid},{q},{a}\n'
open('questions.csv','w').write(questions)
print('Created trustgate.yaml and questions.csv')
"trustgate version
trustgate --help
trustgate certify --helpExpected: version number, all commands listed, all flags shown (including --alpha, --concurrency, --auto-judge, --min-reliability).
trustgate certifyExpected:
- "Measuring API latency..." spinner
- Pre-flight Estimate table with measured latency and estimated time
- Cost / Reliability Tradeoff table with Est. Time per K
- Prompt:
Proceed? Enter Y, N, or a number to change K - Type
Nto abort
trustgate certify --yesExpected:
- Spinner with estimated time
- TrustGate Certification Result table
- Plain-English explanation of Reliability Level and M*
- Docs link
# JSON
trustgate certify --yes --output json
# CSV
trustgate certify --yes --output csv
# To file
trustgate certify --yes --output json --output-file result.json
cat result.jsontrustgate certify --yes --verboseExpected: result table + Coverage by Alpha table.
# 99% confidence — stricter, M* may be larger
trustgate certify --yes --alpha 0.01
# 90% confidence — looser, M* may be smaller
trustgate certify --yes --alpha 0.10trustgate certify --cost-per-request 0.05Expected: pre-flight shows $0.0500 per request. Type N to abort.
# Conservative (safe for rate-limited APIs)
trustgate certify --yes --concurrency 5
# Aggressive (faster, may hit rate limits)
trustgate certify --yes --concurrency 30# Should PASS
trustgate certify --yes --min-reliability 50
echo "Exit code: $?"
# Should FAIL
trustgate certify --yes --min-reliability 99
echo "Exit code: $?"Expected: exit code 0 for PASS, 1 for FAIL.
trustgate sample --questions questions.csvtrustgate cache stats
trustgate cache cleartrustgate calibrate --export questionnaire.html --yes
open questionnaire.html # macOS (or xdg-open on Linux)Expected:
- "Selected N questions for human calibration (out of 50 total)"
- HTML file opens in browser
- Questions with randomized answer buttons (no ranks, no frequencies)
- "Download Labels" at the end
trustgate calibrate --serve --port 9999 --yesExpected: browser opens, review UI, admin at /admin. Press Ctrl+C when done.
After reviewing in the questionnaire or web UI:
trustgate certify --ground-truth labels.json --yestrustgate certify --auto-judge --yesExpected: "Auto-judging with LLM..." then certification result.
# Generate ground truth file
python3 -c "
import csv, json
labels = {}
with open('questions.csv') as f:
for row in csv.DictReader(f):
labels[row['id']] = row['acceptable_answers']
json.dump(labels, open('ground_truth.json', 'w'), indent=2)
"
trustgate compare \
--models gpt-4.1-mini,gpt-4.1-nano \
--task-type llm \
--questions questions.csv \
--ground-truth ground_truth.jsonRun each block with python3 -c "..." or in a Python shell.
from theaios import trustgate
result = trustgate.certify(config_path="trustgate.yaml")
print(f"Reliability: {result.reliability_level:.1%}")
print(f"M* (at {1-result.target_alpha:.0%} confidence): {result.m_star}")
print(f"Coverage: {result.coverage:.3f}")
print(f"Capability Gap: {result.capability_gap:.1%}")from theaios.trustgate import sample_and_profile
from theaios.trustgate.config import load_config, load_questions
config = load_config("trustgate.yaml")
questions = load_questions("questions.csv")
profiles = sample_and_profile(config, questions)
for qid in list(profiles.keys())[:5]:
print(f"{qid}: {profiles[qid]}")from theaios.trustgate import diagnose_profiles, sample_and_profile
from theaios.trustgate.config import load_config, load_questions
config = load_config("trustgate.yaml")
questions = load_questions("questions.csv")
profiles = sample_and_profile(config, questions)
diag = diagnose_profiles(profiles)
print(f"Status: {diag.status}")
print(f"Mean consensus: {diag.mean_consensus:.2f}")
print(f"Warnings: {diag.warnings}")from theaios.trustgate import sample_and_profile, generate_questionnaire
from theaios.trustgate.config import load_config, load_questions
config = load_config("trustgate.yaml")
questions = load_questions("questions.csv")
profiles = sample_and_profile(config, questions)
path = generate_questionnaire(questions, profiles, "test_questionnaire.html")
print(f"Generated: {path}")from theaios.trustgate import sample_and_profile, auto_judge_labels
from theaios.trustgate.config import load_config, load_questions
config = load_config("trustgate.yaml")
questions = load_questions("questions.csv")
profiles = sample_and_profile(config, questions)
q_texts = {q.id: q.text for q in questions}
labels = auto_judge_labels(q_texts, profiles, config.canonicalization.judge_endpoint)
print(f"Labeled {len(labels)} questions")
for qid in list(labels.keys())[:5]:
print(f" {qid}: {labels[qid]}")from theaios.trustgate import TrustGate, certify
from theaios.trustgate.config import load_config
config = load_config("trustgate.yaml")
result = certify(config=config)
gate = TrustGate(config=config, certification=result)
response = gate.query("What is the capital of France?")
print(f"Answer: {response.answer}")
print(f"Reliability: {response.reliability_level:.1%}")
print(f"Mode: {response.mode}")from theaios.trustgate import TrustGate, certify
from theaios.trustgate.config import load_config
config = load_config("trustgate.yaml")
result = certify(config=config)
gate = TrustGate(config=config, certification=result, mode="sampled")
response = gate.query("What is the capital of France?")
print(f"Answer: {response.answer}")
print(f"Prediction set: {response.prediction_set}")
print(f"Consensus: {response.consensus:.0%}")
print(f"Singleton: {response.is_singleton}")from theaios.trustgate import certify
from theaios.trustgate.reporting import export_json, export_csv, print_certification_result
result = certify(config_path="trustgate.yaml")
print_certification_result(result, verbose=True)
print(export_json(result)[:200] + "...")from theaios.trustgate import Canonicalizer, register_canonicalizer, get_canonicalizer
@register_canonicalizer("upper")
class UpperCanonicalizer(Canonicalizer):
def canonicalize(self, question, answer):
return self.preprocess(answer).upper()
c = get_canonicalizer("upper")
print(c.canonicalize("Q?", "The answer is hello"))
from theaios.trustgate.canonicalize import list_canonicalizers
print(f"All canonicalizers: {list_canonicalizers()}")from theaios.trustgate.datasets import load_mmlu
questions = load_mmlu(subjects=["abstract_algebra"], n=5)
for q in questions:
print(f"{q.id}: {q.text[:60]}...")| # | Feature | Type | Status |
|---|---|---|---|
| 1 | Version/help | CLI | |
| 2 | Pre-flight + K selection | CLI | |
| 3 | Certify with ground truth | CLI | |
| 4 | JSON/CSV/file output | CLI | |
| 5 | Verbose per-alpha breakdown | CLI | |
| 6 | --alpha for M* confidence | CLI | |
| 7 | Cost per request | CLI | |
| 8 | Concurrency control | CLI | |
| 9 | CI/CD gating (--min-reliability) | CLI | |
| 10 | Sample only | CLI | |
| 11 | Cache stats/clear | CLI | |
| 12 | Export HTML questionnaire | CLI | |
| 13 | Local web UI | CLI | |
| 14 | Certify with human labels | CLI | |
| 15 | Auto-judge (--auto-judge) | CLI | |
| 16 | Model comparison | CLI | |
| 17 | certify() | Python | |
| 18 | sample_and_profile() | Python | |
| 19 | diagnose_profiles() | Python | |
| 20 | generate_questionnaire() | Python | |
| 21 | auto_judge_labels() | Python | |
| 22 | TrustGate passthrough | Python | |
| 23 | TrustGate sampled | Python | |
| 24 | Reporting | Python | |
| 25 | Custom canonicalizer | Python | |
| 26 | Built-in datasets | Python |
# macOS / Linux
cd .. && rm -rf trustgate-test
# Windows (PowerShell)
cd ..; Remove-Item -Recurse -Force trustgate-test