Skip to main content
Add ANTHROPIC_API_KEY or OPENAI_API_KEY to your environment variables before using these helpers. askClaudeTextValidation and askChatGPTTextValidation share the same signature and return shape, and can be swapped with no other changes to your test.

Examples

Assert that an AI response is valid and within the token budget
Use ChatGPT as the judge model instead

When to use

  • Your app surfaces AI-generated content (summaries, prep notes, chat responses) that must be checked for accuracy.
  • Your app’s AI feature must not introduce contradictions or hallucinations relative to source material.
  • Your app has a quality bar for AI output that a simple string match cannot enforce.
  • Your app sends AI prompts that could drift in cost and you need to assert token budgets.
  • Your app uses different AI providers and you want a consistent validation interface across both.

Helpers

askClaudeTextValidation

Sends the original prompt and candidate response to Claude and returns a structured verdict. Conforms to the Anthropic Messages API.

askChatGPTTextValidation

Same signature and return shape as askClaudeTextValidation. Uses the OpenAI Responses API with structured JSON output. Conforms to the OpenAI Responses API. NPM needed: openai@latest

Return shape

Both helpers return { validation, usage } with the same structure.

Full sample test

Last modified on May 20, 2026