Back to Playbook
AI Engineering6 min read

How We Evaluate AI Systems

Raw trial-and-error prompting fails in production. Here is our step-by-step framework to test, validate, and measure LLM outputs programmatically.

The Trap: Ad-Hoc Prompt Testing

Most teams build AI features by writing a prompt, testing it with 5 sample inputs, seeing that it works, and shipping it. Three days later, clients report edge-case failures, hallucinations, or broken JSON formats. Programmatic validation is non-negotiable for production AI.

Step 1: Build a Baseline Dataset

You cannot optimize what you do not measure. We assemble a test suite of 100 to 500 representative inputs, including typical scenarios, edge cases, and known failure-inducing data. This becomes our baseline test regression suite.

Step 2: Implement Deterministic Schema Checking

Before checking if the LLM output is 'smart,' we check if it is structurally correct. If the system expects JSON, we validate it against a strict schema. We use libraries like Zod or custom parsers to assert types and structures immediately at the gateway.

// Standard schema validation wrapper export async function validateAIOutput(rawText: string, schema: any): Promise { try { const cleanJSON = rawText.substring(rawText.indexOf('{'), rawText.lastIndexOf('}') + 1); const parsed = JSON.parse(cleanJSON); return schema.parse(parsed); } catch (error) { throw new Error("AI output failed to conform to the requested structural contract."); } }

Step 3: Programmatic Assertions

We write deterministic assertions checking for business-critical conditions:

  • Does the response contain banned words or competitor links?
  • Are all required database IDs referenced correctly in the output text?
  • Is the string length within layout constraints?

Step 4: Programmable LLM Grading

For subjective metrics (such as tone, alignment, or correctness), we use a fast, cost-effective model (like Claude 3 Haiku) as a grader. We prompt the grader with strict rubrics and require a numeric score and a one-sentence justification. We run this test suite in CI/CD pipelines to ensure prompt modifications don't cause regressions.

Looking to implement this architecture?

We partner with tech companies to resolve complexity, write robust codebases, and optimize system speed.

Work With Us