PromptEval
API Reference

Assertions

Assertions define what properties each output must satisfy. Every assertion maps to one of four evaluation channels depending on the type.

Deterministic assertions

Evaluated in the SDK — no API call, no cost, <1ms.

valid-jsonFree

Output is valid JSON.

{ type: "valid-json" }
max-wordsFree

Output word count does not exceed the specified value.

{ type: "max-words", value: 400 }
min-wordsFree

Output word count is at least the specified value.

{ type: "min-words", value: 50 }
containsFree

Output contains the specified string (exact match, case-sensitive by default).

{ type: "contains", value: "Order #12345" }
not-containsFree

Output does not contain the specified string.

{ type: "not-contains", value: "competitor_brand" }
starts-withFree

Output begins with the specified string.

{ type: "starts-with", value: "Dear" }
languageFree

Output is written in the specified language (ISO 639-1 code).

{ type: "language", value: "en" }
matches-regexFree

Output matches the specified regular expression.

{ type: "matches-regex", pattern: "^\\d{4}-\\d{2}-\\d{2}$" }

Encoder assertions

Routed to DeBERTa-v3 or ModernBERT. ~$0.0001/call, 10–50ms.

not-toxicEncoder

Output does not contain hateful, threatening, obscene, or harassing content. Returns a toxicity score; passes if score < 0.1 by default.

{ type: "not-toxic" }
{ type: "not-toxic", threshold: 0.05 }  // stricter
no-piiEncoder

Output does not contain personally identifiable information (names, emails, phone numbers, addresses, SSNs).

{ type: "no-pii" }
sentimentEncoder

Output sentiment matches the specified value: positive, negative, or neutral.

{ type: "sentiment", value: "positive" }

Semantic assertions

Routed to the Glider judge model. ~$0.001/call, 100–500ms.

semanticSemantic Judge

The output satisfies the criterion described in natural language. The threshold field (0–1) sets the minimum score to pass. Defaults to 0.7.

1// These all route to the semantic judge:
2{ type: "semantic", criterion: "response demonstrates genuine empathy toward the customer", threshold: 0.75 }
3{ type: "semantic", criterion: "explanation is clear to a non-technical reader", threshold: 0.80 }
4{ type: "semantic", criterion: "code review is constructive and specific", threshold: 0.70 }
5{ type: "semantic", criterion: "answer is factually correct given the provided context", threshold: 0.90 }
6{ type: "semantic", criterion: "response maintains a professional but friendly tone", threshold: 0.75 }

Writing effective semantic criteria

  • → Be specific. "Demonstrates genuine empathy" is better than "good response".
  • → Describe the positive case, not the negative. "Stays on topic" not "doesn't go off topic".
  • → Avoid compound criteria in one assertion — split them into two.

Common assertion patterns

patterns.ts
1// Customer support bot
2assertions: [
3 { type: "not-toxic" },
4 { type: "no-pii" },
5 { type: "max-words", value: 250 },
6 { type: "semantic", criterion: "acknowledges the customer's concern before offering a solution", threshold: 0.75 },
7 { type: "semantic", criterion: "offers a concrete next step or resolution", threshold: 0.80 },
8]
9
10// Code review assistant
11assertions: [
12 { type: "valid-json" }, // if outputting structured review
13 { type: "min-words", value: 30 },
14 { type: "semantic", criterion: "identifies at least one specific improvement", threshold: 0.80 },
15 { type: "semantic", criterion: "tone is constructive rather than critical", threshold: 0.75 },
16]
17
18// RAG answer quality
19assertions: [
20 { type: "max-words", value: 150 },
21 { type: "semantic", criterion: "answer is grounded in the provided context and does not hallucinate", threshold: 0.85 },
22 { type: "semantic", criterion: "answer directly addresses the question asked", threshold: 0.80 },
23]