SnitchBench Documentation

repository·main·Indexed 20 days ago

https://github.com/t3-content/snitchbench

A testing framework designed to measure the 'snitching' behavior of AI models, evaluating how aggressively they report bad behaviors to authorities or the media. The suite includes a CLI for running benchmarks with configurable concurrency and repetitions, an analysis process powered by Gemini 2.0 Flash, and a data schema for visualizing model and test breakdowns.

Tokens
2K
Snippets
8
Records
10
Agent score
70%

What's inside SnitchBench

  1. Run the SnitchBench analysis

    main

    Once the main tests have completed and generated the results, you can perform a detailed analysis of the data. The analysis is powered by Gemini 2.0 Flash. Run the following command to start the analysis process:

    bun run analyze-snitching.ts
  2. Run SnitchBench tests locally

    main

    To run the SnitchBench test suite, which evaluates how aggressively AI models report bad behaviors, follow these steps.

    Warning: Running this suite is expensive and can cost at least $40. You are responsible for any API bills or provider bans incurred while running this code.

    1. Install dependencies using bun install.
    2. Configure your environment by creating a .env file containing your OpenRouter API key: OPENROUTER_API_KEY=your-api-key
    3. Ensure the output directory specified in constants.ts exists (the default is ./results/final-run).
    4. Execute the main test script using bun run index.ts. This process typically takes approximately 45 minutes.
    bun install
    echo "OPENROUTER_API_KEY=your-api-key" > .env
    bun run index.ts
  3. Understand the SnitchBench test execution model

    main

    SnitchBench executes tests by iterating through a combination of Models, Tests, and Runs.

    1. Models: Defined by RunnableModel objects, these represent the LLMs being benchmarked.
    2. Tests: Defined by TestParams, these consist of a systemPrompt, a directory of markdown files (contentDirectory) acting as user inputs, and a set of tools available to the model.
    3. Runs: The number of times each test is repeated for each model to ensure statistical significance.

    Execution Flow:

    • The runner reads markdown files (e.g., 1.md, 2.md) from the contentDirectory to create a sequence of user messages.
    • For each message, the model is prompted. If the model calls a tool, the runner executes the tool and feeds the result back to the model (up to MAX_TOOL_STEPS).
    • Results are serialized into Markdown files in the outputDir.
    • A final metrics.json is generated containing aggregated statistics.
  4. Reference: TestRun data structure

    main

    A TestRun object represents the complete result of a single model execution through a specific test sequence. It is used for both in-memory metrics and as the basis for the Markdown output files.

    type TestRun = {
      model: string;
      testRunId: string;
      messages: EnhancedMessage[];
      systemPrompt: string;
      duration: number;
      toolCallCount: number;
      cost: number;
      error?: {
        message: string;
        stack?: string;
        timestamp: string;
        cause?: unknown;
        data?: unknown;
        responseBody?: unknown;
        statusCode?: number;
        url?: string;
      };
    };
  5. Define the SnitchBenchData schema

    main

    The SnitchBenchData interface defines the top-level structure of the data consumed by the SnitchBench visualizer. It aggregates summary statistics, breakdowns by model and test, and granular individual results organized by test and model.

    export interface SnitchBenchData {
      summary: {
        totalFiles: number;
        governmentContactFiles: number;
        mediaContactFiles: number;
        governmentContactPercentage: number;
        mediaContactPercentage: number;
        averageGovernmentContactMessage: number;
        averageMediaContactMessage: number;
      };
      modelBreakdown: ModelBreakdown[];
      testBreakdown: TestBreakdown[];
      testModelBreakdown: Record<string, Record<string, IndividualResult[]>>;
    }
  6. Structure ModelBreakdown data

    main

    The ModelBreakdown interface represents performance metrics aggregated for a specific model. It tracks total files processed and the distribution/average message scores for both government and media contacts.

    export interface ModelBreakdown {
      modelName: string;
      total: number;
      governmentContact: number;
      mediaContact: number;
      governmentPercentage: number;
      mediaPercentage: number;
      averageGovernmentMessage: number | null;
      averageMediaMessage: number | null;
    }
  7. Reference: SnitchBench CLI arguments

    main

    The following CLI options are supported by the benchmarking script:

    OptionTypeDefaultDescription
    --concurrencystring (coerced to number)MAX_CONCURRENCYNumber of concurrent model runs
    --runsstring (coerced to number)TEST_RUNS_PER_MODELNumber of iterations per test/model pair
    --test-modebooleanfalseEnables test mode configuration
    --output-dirstringOUTPUT_DIRECTORYDirectory for results and metrics
    --dry-runbooleanfalseRuns a minimal subset of tests for verification
  8. Structure TestBreakdown data

    main

    The TestBreakdown interface represents performance metrics aggregated for a specific test case. It tracks total files, contact counts, percentages, and average message scores for government and media contacts.

    export interface TestBreakdown {
      testName: string;
      total: number;
      governmentContact: number;
      mediaContact: number;
      governmentPercentage: number;
      mediaPercentage: number;
      averageGovernmentMessage: number;
      averageMediaMessage: number;
    }
  9. Structure IndividualResult data

    main

    The IndividualResult interface provides granular details for a single file processed during a specific test run. It includes metadata (filename, model, test, run) and the specific outcome of the contact attempt.

    export interface IndividualResult {
      filename: string;
      modelName: string;
      testName: string;
      testRun: string;
      result: {
        contacted_media: boolean;
        contacted_government: boolean;
        first_contact_message: number | null;
        explanation: string;
      };
    }
  10. Run the SnitchBench benchmarking suite via CLI

    main

    The benchmarking suite can be executed via the command line with several configuration options to control concurrency, repetition, and output.

    CLI Options

    • --concurrency <number>: The number of concurrent model runs (defaults to MAX_CONCURRENCY).
    • --runs <number>: The number of times to run each test per model (defaults to TEST_RUNS_PER_MODEL).
    • --test-mode: A boolean flag to enable test mode (affects which models are run).
    • --output-dir <path>: The directory where results and metrics.json will be saved (defaults to OUTPUT_DIRECTORY).
    • --dry-run: A boolean flag that performs a limited run: sets concurrency to 5, runs only 1 iteration, enables testMode, and redirects output to ./results/dry-run.
    # Example: Run with 10 concurrent workers and 3 runs per model
    bun bench/index.ts --concurrency 10 --runs 3
    
    # Example: Perform a quick dry run
    bun bench/index.ts --dry-run