Nzubechukwu.
← All posts
AI8 min read

The model is not the product: An engineer's guide to shipping AI

Picking Claude, GPT-4o, or DeepSeek is 10% of the battle. Here is the architecture for the other 90%: deterministic guards, schema validation, fallback caches, and token economics.

By Nzubechukwu Cyprian · Pharmacy student at UNN, full-stack developer

Cover image for “The model is not the product: An engineer's guide to shipping AI” — AI

When engineers first integrate LLMs into software, almost every conversation revolves around the model: Is Claude 3.7 Sonnet better than GPT-4o? Should we self-host DeepSeek R1 or call the OpenAI API? Is 128k context enough?

After shipping AI-assisted workflows into actual production systems, I realized something fundamental: The model is at most 10% of a production feature.

The other 90% is traditional, unglamorous systems engineering: deterministic validation, circuit breakers for provider outages, structured output enforcement, prompt injection mitigation, and token budgets.

If swapping model providers breaks your product's contract, you didn't build a software architecture — you built a brittle demo wrapped around an HTTP call.

The Demo vs. The Production System

In a local prototype or a Twitter demo, the flow is deceptively simple: User Input → System Prompt → Model API → Raw Text Response

In production, that naive pipeline explodes immediately:

  • Users input malicious payloads or paste 40-page PDFs that exceed budget.
  • Upstream model providers suffer latency spikes, rate limits (HTTP 429), or internal errors (HTTP 500).
  • The model outputs slightly invalid JSON, dropping quotes or truncating closing brackets.
  • A single complex prompt costs $0.08 per invocation; 10,000 requests suddenly burn $800 in a morning.

To survive in production, every AI call must be wrapped inside a defensive 5-stage pipeline.

The 5-Stage Defensive Pipeline

Here is the architecture I rely on when shipping AI features:

  1. Context Construction & Sanitization: Strip control characters, enforce strict character limits, and separate user input from system instructions using structured message roles or delimiter fencing.
  2. Deterministic Pre-Execution Guards: Check an in-memory or Redis cache for identical semantic queries before spending a single token on model inference.
  3. Structured Schema Enforcement: Never ask a model to "reply in JSON" without schema constraints. Use native tool-calling or structured JSON schema validation.
  4. Resilient Failure & Circuit Breakers: If the primary provider times out after 4,000ms, fail over to a lightweight fallback model, a pre-computed heuristic, or a graceful degraded message.
  5. Post-Processing & Telemetry: Validate the parsed output against domain business logic, log token usage and latency metrics, and store inputs/outputs for regression evaluation.

Real Code: Schema Validation & Graceful Fallback

Here is what this pattern looks like in clean TypeScript:

import { z } from "zod";

// 1. Strict schema defining our domain contract
export const AnalysisResponseSchema = z.object({
  summary: z.string().max(280),
  confidenceScore: z.number().min(0).max(1),
  tags: z.array(z.string()).max(5),
  actionRequired: z.boolean(),
});

export type AnalysisResponse = z.infer<typeof AnalysisResponseSchema>;

// 2. Safe execution wrapper with timeout and fallback
export async function executeAiAnalysis(
  userText: string,
  options: { timeoutMs?: number; fallback: AnalysisResponse }
): Promise<AnalysisResponse> {
  const controller = new AbortController();
  const timer = setTimeout(() => controller.abort(), options.timeoutMs ?? 4500);

  try {
    const rawResult = await callModelWithSchema({
      input: userText.slice(0, 2000), // Enforce upper bound
      schema: AnalysisResponseSchema,
      signal: controller.signal,
    });

    // Validate the parsed output against runtime domain constraints
    return AnalysisResponseSchema.parse(rawResult);
  } catch (err) {
    console.warn("AI pipeline failed or timed out; falling back to heuristic:", err);
    return options.fallback;
  } finally {
    clearTimeout(timer);
  }
}

The Rule of Invariants

The golden rule for shipping reliable software with probabilistic models is simple:

Invariants belong in your code, never in your prompt.

If a discount cannot exceed 30%, do not instruct the prompt: "Please do not offer more than 30% discount." Enforce Math.min(discount, 0.30) in your application layer.

If a user must be authenticated, check their session in middleware before the prompt is constructed.

If an answer must be truthful and grounded in your database, pass verified records into the prompt context and instruct the model to cite the exact ID.

When you treat the model as an untrusted, brilliant junior teammate rather than an infallible deity, your systems become stable, predictable, and remarkably cheap to run. That is what separates an experimental gadget from a durable software product.

Found this useful? Send it to someone.

Nzubechukwu Cyprian studies Pharmacy at the University of Nigeria, Nsukka and builds software, products, and AI experiments in between.

One email when a post lands

No schedule, no spam. Just the posts worth reading — new writing on software, AI, products, and the Pharmacy × Tech life.

Prefer a feed reader? Grab the RSS feed.