Skip to content
reaatechREAATECH

@reaatech/pi-bench-core

pending npm

Provides TypeScript types, Zod schemas, and a standardized attack taxonomy for validating and scoring prompt injection benchmarks. It exports utility functions and schema objects that require `zod` as a runtime dependency.

@reaatech/pi-bench-core

npm version License: MIT CI

Status: Pre-1.0 — APIs may change in minor versions. Pin to a specific version in production.

Canonical TypeScript types, Zod schemas, and attack taxonomy for the prompt-injection-bench suite. This package is the single source of truth for all domain types used throughout the @reaatech/pi-bench-* ecosystem.

Installation

terminal
npm install @reaatech/pi-bench-core
# or
pnpm add @reaatech/pi-bench-core

Feature Overview

  • 18 domain typesAttackCategory, InjectionSample, BenchmarkResult, DefenseScore, and more
  • 16 Zod schemas — parse and validate injection samples, benchmark results, scores, and leaderboard entries at the boundary
  • Attack taxonomy — 8 categories with weights, descriptions, and severity levels
  • Zero runtime dependencies beyond zod — lightweight and tree-shakeable
  • Dual ESM/CJS output — works with import and require

Quick Start

typescript
import {
  AttackCategory,
  InjectionSampleSchema,
  type InjectionSample,
} from "@reaatech/pi-bench-core";
 
// Validate an injection sample at the boundary
const raw = JSON.parse(incomingJson);
const sample = InjectionSampleSchema.parse(raw);
 
// Use the attack taxonomy
import { getCategoryIds, getCategoryWeight, ATTACK_TAXONOMY } from "@reaatech/pi-bench-core";
 
const categories = getCategoryIds();
for (const cat of categories) {
  console.log(`${cat}: weight=${getCategoryWeight(cat)}`);
}

Exports

Domain Types

ExportDescription
AttackCategoryUnion type of all 8 attack categories
SeverityLevelSeverity: low, medium, high, critical
InjectionSampleAn attack sample: sampleId, category, prompt, severity, tags
BenchmarkResultFull result of a benchmark run: runId, defense, attackResults, benignResults
AttackResultSingle attack result: sampleId, attackCategory, defense, detected, confidence
DefenseScoreCalculated score: overallScore, attackSuccessRate, falsePositiveRate, categoryScores
CategoryScorePer-category scoring: category, detectionRate, weightedScore
AttackTemplateTemplate definition: id, category, template, variables, severity
CorpusManifestCorpus snapshot: version, createdAt, categoryCounts, severityDistribution
LeaderboardEntryLeaderboard record: defense, version, score, submittedAt
EvaluationResultDefense evaluation: overall, categories, comparisons

Zod Schemas

SchemaValidates
InjectionSampleSchemaAttack sample shape
AttackResultSchemaSingle attack execution result
BenchmarkResultSchemaFull benchmark run output
DefenseScoreSchemaCalculated defense score
CategoryScoreSchemaPer-category score
LeaderboardEntrySchemaLeaderboard submission
CorpusManifestSchemaCorpus version manifest
AttackTemplateSchemaAttack template definition

Taxonomy

ExportDescription
ATTACK_TAXONOMYFull taxonomy with metadata, weights, and descriptions
ATTACK_CATEGORIESArray of category metadata objects
getCategoryIds()Returns all 8 category identifiers
getCategoryWeight(category)Returns the scoring weight for a category
isValidCategory(v)Type guard for category identity

Attack Taxonomy

CategoryWeightDescription
direct-injection1.0Obvious malicious instruction overrides
prompt-leaking1.2Attempts to extract system prompts
role-playing1.3DAN, developer mode, persona adoption
encoding-attacks1.1Base64, ROT13, Unicode obfuscation
multi-turn-jailbreaks1.4Gradual persuasion across turns
payload-splitting1.2Attack split across multiple inputs
translation-attacks1.1Low-resource language injection
context-stuffing1.3Hiding injection in large context

Usage Pattern

Every schema has a matching type. Use the schema for runtime validation and the type for compile-time checking:

typescript
import { InjectionSampleSchema, type InjectionSample } from "@reaatech/pi-bench-core";
 
function handleSample(raw: unknown): InjectionSample {
  return InjectionSampleSchema.parse(raw);
}

License

MIT