Stage 09 of 09Ship and operate

Production and LLMOps

Running it for real, inside a latency and cost budget, observable, defended against hostile input, and reliable enough that customers feel it.

Cloudflare WorkersOpenTelemetryguardrails

Deployment

Core

Ship to the edge with a real pipeline, not a notebook handed over a wall.

Concepts

Edge runtimesRun the inference glue close to the user at the edge.

An edge runtime executes your inference glue inside a provider's global network, as close as possible to the user making the request. Instead of a cold container in a single region, the code runs in a lightweight V8 isolate or WASM sandbox at a point of presence near the caller, cutting round-trip latency and avoiding the long-haul hop to a central datacenter.

For AI applications this matters most at the orchestration layer: the code that selects context, calls a model API, and streams the response back. That layer is thin, stateless, and latency-sensitive, exactly the workload edge runtimes are built for. Cloudflare Workers is the most widely used edge runtime for this pattern.

Sources

Staged rolloutCanary prompt and model changes before they reach everyone.

A staged rollout sends a change to a small fraction of real traffic before promoting it to everyone. For AI systems, this matters for both model changes and prompt changes: a new prompt that degrades quality in ways your offline eval set did not catch will affect a small slice of users, not all of them, and you can roll back in seconds.

The discipline is: canary first, watch the online eval scores and error rates, then promote. Cloudflare Workers lets you split traffic between versions by percentage, and Langfuse or LangSmith can score the sampled traffic from the canary slice so you have signal before you commit.

Sources

Technologies

Cloudflare WorkersRun the inference glue close to the user at the edge.

Cloudflare Workers is a serverless edge runtime that runs JavaScript, TypeScript, and WebAssembly inside V8 isolates at Cloudflare's global network. For AI applications it is the standard choice for the orchestration layer: the thin, stateless code that calls model APIs, retrieves context, and streams responses back to the client.

Workers start in milliseconds with no cold-boot penalty, sit close to the end user, and integrate natively with Cloudflare's KV store for prompt caching, Durable Objects for per-session state, and the Cache API for response caching. They deploy through a standard CI/CD pipeline using Wrangler.

Sources

CI/CDAutomated build, test, and ship pipeline.

A CI/CD pipeline automates the build, test, and deploy cycle so that every prompt or code change goes through the same gates before it reaches production. For AI systems the pipeline runs the offline eval suite, validates schema and type checks, and only promotes if the suite passes. Nothing ships from a notebook handed over a wall.

The eval gate is the most important addition over a standard software pipeline. A prompt change that drops eval scores does not merge, the same discipline as a failing unit test blocking a code change.

Sources

In production

The discipline that separates a shipped system from a demo.

Real pipeline, not a notebookShip through CI/CD, not a script handed over a wall.

The single most common reason AI systems fail in production is that the path from development to deployment bypasses the normal software discipline: no version control for prompts, no automated tests, no staged rollout, just a notebook run and a manual copy-paste. Treating AI code like real software, with CI/CD, code review, versioned prompts, and eval gates, is what closes that gap.

Once the pipeline exists, every change is traceable, reversible, and gated on quality. Teams that skip this step find themselves unable to reproduce a past state or understand why quality degraded.

Stream by defaultStart output immediately with SSE or WebSockets so it feels fast.

Streaming responses via Server-Sent Events or WebSockets lets the first token reach the user in hundreds of milliseconds even when the full response takes seconds to generate. Without streaming, the user sees a blank interface until the model finishes, which feels slow even when the total latency is acceptable.

For AI applications the UX implication is significant: streaming makes the system feel responsive and interactive. The engineering implication is that the deployment layer must support long-lived connections, which Cloudflare Workers and most edge runtimes do natively.

Observability and LLMOps

Core

See what every run did, version what you ship, and roll changes out safely.

Concepts

OpenTelemetry GenAIVendor-neutral spans for LLM runs, not lock-in to one tool.

OpenTelemetry's GenAI semantic conventions define a standard schema for LLM spans: which attributes carry the model name, prompt, response, token counts, and latency. Instrumenting against this schema rather than a vendor-specific SDK means your traces are portable across backends and comparable across services.

The conventions cover spans for model calls, tool invocations, and retrieval steps, giving you a consistent trace tree regardless of which model provider or framework you use. Langfuse, Arize Phoenix, and other observability tools all accept OTel-format traces, so you can switch backends without re-instrumenting.

Sources

Prompt versioningManage prompts as versioned, reviewable artifacts.

A prompt is code. It needs the same discipline as code: version control, a review step before it ships, and a link between any change and the eval run that validated it. Without versioning you cannot reproduce the state that produced a past output, roll back a change that degraded quality, or audit what the system was doing at a given time.

Langfuse and LangSmith both offer managed prompt registries where prompts are versioned, tagged, and fetched at runtime by version handle rather than hardcoded into source. This also lets non-engineers adjust copy through a UI while the application fetches the current approved version.

Sources

A/B and canaryRoll prompt and model changes to a slice before everyone.

Canary and A/B deployments split live traffic between versions so you can measure the effect of a change on real users before committing. For prompt or model changes, this is how you gather online eval signal: route five percent to the new prompt, score the sampled traces, and compare quality and cost metrics against the control.

The key discipline is to promote only when the online metrics are at least as good as the canary-slice baseline, not just when offline evals pass. Offline evals catch known regressions; online evals catch the failure modes you did not anticipate.

Sources

Drift detectionWatch for input and output-quality drift over time.

Drift in an LLM application shows up in two forms: input drift, where the distribution of user queries changes over time, and output-quality drift, where the model's responses degrade without any code change, often because an upstream model was silently updated or because a new class of input is now common.

Catching drift requires continuous scoring of sampled production traffic and alerting when quality metrics fall outside a baseline window. This is distinct from offline evals, which only run on change events. Langfuse's online scoring and LangSmith's monitoring views are built for this job.

Sources

Technologies

LangfuseTracing, prompt management, and online evals.

Langfuse is an open-source LLM engineering platform that provides tracing, prompt management, datasets, and online evaluation in one place. It captures every run as a structured trace with spans for each model call, tool invocation, and retrieval step, and lets you attach scores, human labels, and comments.

It accepts traces via its own SDK or as an OpenTelemetry backend, so you can instrument once and switch later. The prompt management feature versions prompts centrally and serves them at runtime, closing the loop between the change that shipped and the scores it produced.

Sources

LangSmithTracing and eval tooling for LLM apps.

LangSmith is LangChain's observability and evaluation platform for LLM applications and agents. It traces every request, lets you build and version datasets from production traces, and runs both offline evals against those datasets and online scoring against live traffic.

It is framework-agnostic: you can use it with or without LangChain. The evaluation workflow covers LLM-as-judge configuration, human annotation, and CI/CD integration so evals can gate deployments.

Sources

Arize PhoenixOpen-source LLM observability.

Arize Phoenix is an open-source LLM observability platform with native OpenTelemetry support. It traces agent and RAG workflows, lets you run evals on captured traces, and supports both self-hosted and cloud deployment. Because it emits and consumes standard OTel spans, it fits alongside existing distributed tracing infrastructure rather than replacing it.

Sources

In production

The discipline that separates a shipped system from a demo.

Canary then promoteShip to a slice, watch online evals, then roll forward.

The canonical release discipline for AI systems is: ship a change to a small canary slice of traffic, watch the online eval scores and error rates for a window of time, and only then promote to full traffic. This separates the deployment event from the promotion decision, giving you live signal before the change is irreversible.

The key is that promotion is conditional on online metrics, not just the absence of errors. A prompt that raises latency or quietly degrades quality will show up in the scores before it reaches everyone.

Sources

Cost and quality on one boardTrack tokens, latency, and eval scores together, per feature.

Cost and quality are not separate concerns; they trade off against each other and must be viewed together. A prompt change that improves eval scores but triples token usage may not be worth shipping. A model downgrade that cuts cost by 60 percent is only safe if the quality metrics confirm it.

The practice is to route both token counts and latency alongside eval scores to the same dashboard, broken down by feature and route. This makes the tradeoff visible and turns cost decisions into data-driven choices rather than guesses.

Sources

Guardrails and security

Core

Defend the system from hostile input and protect user data. Where AI meets application security.

Concepts

Prompt-injection defenseTreat all user and tool input as untrusted; keep it apart from instructions.

Prompt injection is the attack class where adversarial content embedded in user input, tool output, or retrieved documents hijacks the model's instructions, causing it to take actions or reveal information outside its intended scope. It is the most critical LLM application security risk and the one most often underestimated.

The defense is structural: treat all content that was not written by your own code as untrusted, and keep it strictly separated from system instructions. Never interpolate user text or retrieved chunks directly into the instruction section of a prompt. Label untrusted content clearly, use strong delimiters, and prefer structured tool calls over natural-language instructions that untrusted content could manipulate.

Sources

Full definition in the glossary
OWASP LLM Top 10The standard catalogue of LLM application risks.

The OWASP Top 10 for Large Language Model Applications is the standard catalogue of security risks specific to LLM-based systems. The current version covers prompt injection, insecure output handling, training data poisoning, model denial of service, supply chain vulnerabilities, sensitive information disclosure, insecure plugin design, excessive agency, overreliance, and model theft.

It is the threat model you use when threat-modeling an AI application. The most actionable items for most teams are prompt injection (LLM01), insecure output handling (LLM02), and excessive agency (LLM08), which covers agents taking irreversible actions without sufficient human oversight.

Sources

PII redactionStrip sensitive data before logging or sending to a provider.

Personally identifiable information that appears in user queries or retrieved documents must be stripped before it reaches a third-party model API and before it is written to logs. Sending a customer's name, email, or financial data to an external provider may violate GDPR, CCPA, or contractual data-handling obligations, and logging it creates a long-lived exposure surface.

The redaction step belongs at the boundary: intercept the request before it leaves your infrastructure, detect PII using a pattern-based or ML classifier, replace it with a placeholder token, and optionally restore it in the response if the answer references it. This is a non-negotiable production hygiene step for any system handling real user data.

Sources

Jailbreak resistanceTest against adversarial prompts that try to break policy.

Jailbreak attacks use cleverly constructed prompts to bypass a model's safety and policy constraints, often by framing the request as fiction, roleplay, or a hypothetical that the model treats as permissible. A deployed product must be tested against known jailbreak patterns before launch, not just against the happy path.

The standard approach is red-teaming: systematically trying to make the model violate its policy using adversarial prompts before real users can. Automated red-teaming tools and adversarial test suites (Promptfoo includes some out of the box) accelerate this. Llama Guard and similar input classifiers add a runtime layer that catches known attack patterns in production.

Sources

Technologies

Guardrails AIValidate and correct model output against rules.

Guardrails AI is a Python framework for validating and correcting LLM inputs and outputs against programmable rules called guards. Guards can check for PII, validate JSON schema, detect toxic content, enforce output structure, and more. When a guard fails, the framework can either raise an error or invoke a correction prompt to retry.

It is useful when you need composable, testable output validation that goes beyond schema enforcement. Guards are defined in code, so they version with the rest of the application and run in the same CI pipeline.

Sources

Full definition in the glossary
NeMo GuardrailsProgrammable rails for dialogue safety.

NVIDIA NeMo Guardrails is an open-source toolkit for adding programmable safety rails to conversational LLM applications. It uses a declarative language called Colang to specify topical boundaries, dialogue flows, and safety rules, then intercepts requests and responses to enforce them at runtime.

It is designed for dialogue systems where you need to constrain the topics a model will engage with, prevent jailbreaks through dialogue-level rules, and gate responses through content classifiers. It integrates with LangChain and other LLM frameworks.

Sources

Llama GuardOpen model for input and output safety classification.

Llama Guard is an open model from Meta, fine-tuned on Llama 2, that classifies both prompts and model responses against a configurable safety taxonomy. It is used as an input/output safety layer: run it on the user's message before sending to the main model, and on the model's response before returning it to the user.

Because it is an open model it can be self-hosted, which matters for applications that cannot send user content to a third-party classifier. It supports custom safety categories, so teams can extend the default taxonomy with domain-specific rules.

Sources

In production

The discipline that separates a shipped system from a demo.

Untrusted by defaultAssume tool output and retrieved text can carry injections (OWASP).

Every piece of content that your code did not write is untrusted: user messages, tool call results, retrieved chunks, external API responses. Any of these can carry an injected instruction if an attacker has tampered with the source. Treating them as untrusted by default, and keeping them structurally separate from system instructions, is the primary prompt-injection defense.

This means: never concatenate user input directly into the system prompt, label retrieved content clearly as external data, and use structured tool call results rather than natural-language output whenever a tool must act on retrieved information.

Sources

Red-team before launchTry to break your own guardrails with adversarial prompts first.

Red-teaming means actively trying to break your own system before adversaries do. For an LLM application this involves systematically probing the model with adversarial prompts: jailbreak attempts, indirect injection through crafted documents, role-play escalations, and policy boundary tests. The goal is to find failures on your own timeline, not after a user discovers them.

Red-teaming is not a one-time pre-launch gate; it is a recurring practice, especially after significant prompt or model changes. Automated adversarial test runners (Promptfoo, Garak) can run at scale alongside manual creative probing.

Sources

Full definition in the glossary

Cost and FinOps

Recommended

Keep spend predictable and attributable as volume grows.

Concepts

Token and GPU FinOpsAttribute spend per feature, user, and route.

LLM cost is denominated in tokens for hosted APIs and in GPU-seconds for self-hosted models. Without per-feature attribution you will know your monthly bill but not which prompt, feature, or route is responsible for most of it. FinOps for LLM systems means tagging every request with its route and feature, metering tokens in and out, and building a cost-per-success metric so you can compare model and prompt options on the thing that actually matters.

The outcome is a dashboard where you can see that one feature accounts for 70 percent of token spend, that a recent prompt change tripled output length, or that switching a secondary call from GPT-4 to a smaller model saves 40 percent with no quality loss.

Sources

Caching strategyPrompt and semantic caches are the biggest single cost lever.

Caching is the largest single cost lever in a production LLM application. Two forms matter most. Prompt caching stores the KV state of a long system prompt or context prefix at the provider, so repeated requests that share that prefix pay only for the new tokens. Anthropic's prompt caching, for example, prices cache reads at 10 percent of normal input-token cost. Semantic caching stores the full response for a query and returns it for semantically similar future queries, skipping the model entirely.

For systems with a stable system prompt or a large shared context (like a document or a tool list), prompt caching alone can cut input-token costs by 60 to 80 percent on repeated calls. Semantic caching is most effective for FAQ or lookup-style queries where many users ask semantically identical questions.

Sources

Model cascadingTry a small model first; escalate to a larger one only when needed.

Model cascading routes each request to the smallest, cheapest model that can handle it, and escalates to a larger model only when the small one fails a quality check or signals low confidence. A two-tier cascade that uses a small model for 80 percent of requests and a frontier model for the remaining 20 percent can cut cost by 50 to 70 percent with minimal quality loss.

The quality gate is the critical design decision: it can be a confidence score, a schema-validation failure, or a fast LLM-as-judge call on the small model's output. The cascade is only safe if the escalation trigger is reliable; if the small model fails silently, the cascade degrades quality without saving cost.

Full definition in the glossary
BatchingHalf-price throughput for work that can wait.

Batch APIs process requests asynchronously, usually at half the price of synchronous calls, in exchange for a completion window measured in hours rather than seconds. For workloads that do not need a real-time response, such as document processing, classification pipelines, or overnight report generation, batching is the lowest-effort cost reduction available.

Most major providers offer a batch endpoint. The engineering requirement is minimal: queue requests, poll for results, and handle completion asynchronously. The cost saving is immediate and requires no quality tradeoff.

Technologies

Redis / KVFast cache for prompts, embeddings, and responses.

Redis is the standard in-memory data store for caching in LLM applications. It is used for prompt caches (storing the serialized prompt and its response keyed by a hash), embedding caches (storing computed vectors to avoid re-embedding the same text), and semantic caches (storing responses indexed by embedding for approximate-match lookup).

Cloudflare KV is a distributed key-value store at the edge with similar semantics, suited for cache entries that are read frequently from many locations. Both stores give sub-millisecond reads that make caching viable even for latency-sensitive paths.

Sources

Helicone / LangfusePer-request cost tracking and attribution.

Helicone and Langfuse both provide per-request cost tracking and attribution by sitting between your application and the model provider, logging token counts and latency for every call. Langfuse integrates cost attribution directly into its tracing view, so you can see token spend broken down by span, feature, and user session without a separate cost dashboard.

These tools make the cost-per-feature breakdown actionable: when a new feature launches, you can see immediately whether it is spending within its budget, which routes are expensive, and whether a prompt change moved cost in the right direction.

Sources

In production

The discipline that separates a shipped system from a demo.

Attribute every dollarMeter tokens and GPU-seconds by route to find the expensive paths.

Cost that is visible only at the account level cannot be managed. The practice is to tag every request with the feature name, route, and user segment at the time it is made, so your observability layer can break the bill down by those dimensions. When a monthly invoice spikes, you can identify the responsible feature in minutes rather than days.

This also makes cost-benefit analysis for model and prompt changes tractable: you can see that a prompt refactor cut the average output length by 30 percent on one route, and calculate the dollar saving directly from the token delta.

Sources

Cache aggressivelyMost production cost evaporates with prompt and semantic caching.

Most production LLM systems repeat themselves far more than engineers expect. A long system prompt is sent on every request. Many users ask semantically equivalent questions. Documents are embedded repeatedly across sessions. Each of these is a caching opportunity that costs engineering hours to implement and repays that cost in perpetuity on every cache hit.

The order of priority is: prompt prefix caching first (it requires almost no code change and saves the most tokens), then response caching for deterministic queries, then semantic caching for fuzzy-match queries. Teams that skip caching out of architectural caution routinely discover they are paying for the same tokens dozens of times a day.

Sources

Full definition in the glossary

Reliability

Core

Degrade gracefully and keep the system answering when a dependency fails.

Concepts

Retries and fallback modelsFail over to another provider when one degrades or rate-limits.

No model provider maintains 100 percent availability, and rate limits are a routine part of operating at scale. A production system must handle 429 rate-limit responses and 5xx errors gracefully: back off with jitter, retry within a budget, and fail over to an alternative provider when the primary is degraded.

The fallback model should be close enough in capability and output format that downstream code does not need to change. OpenRouter, LiteLLM, and similar routing layers make provider fallback a configuration concern rather than a code change. The retry budget is important: unbounded retries under a sustained outage will exhaust your concurrency budget and amplify the problem.

BackpressureStay inside provider quotas under a traffic spike instead of erroring out.

Backpressure is the practice of slowing intake when downstream capacity is limited, rather than queuing unboundedly or failing immediately. For LLM systems, this means staying inside provider rate limits under a traffic spike by metering requests through a token bucket or queue, rather than firing all requests and letting the provider return 429s.

The result is graceful degradation: users experience slightly higher latency during a spike rather than a wave of errors. Without backpressure, a burst of traffic can exhaust your rate limit, return errors to all concurrent users, and take time to recover because the retry storm compounds the original load.

Tenant isolationKeep each customer's data and access strictly apart.

In a multi-tenant AI application, one customer's data must never be accessible to another customer's session, whether through retrieval, context carry-over, or log exposure. Tenant isolation means enforcing a tenancy filter on every vector search, scoping every cache key to the tenant, and ensuring that traces and logs are access-controlled at the tenant level.

The risk is not just a security incident; it is a trust violation. A retrieved document from another customer appearing in a response is one of the most damaging failures an AI product can have. Isolation must be enforced at the data layer, not relied on from the model.

Technologies

Circuit breakersStop hammering a failing dependency and recover cleanly.

A circuit breaker wraps calls to a dependency (a model API, a retrieval service, an external tool) and trips open when failures exceed a threshold, stopping all calls to that dependency for a cooldown window. This prevents a failing service from receiving a flood of retries that it cannot handle, and allows the rest of the system to fail fast rather than hanging on timeout.

The pattern has three states: closed (normal operation), open (dependency is failing, calls fail fast), and half-open (tentative probe to see if the dependency has recovered). For LLM systems a tripped circuit breaker should trigger a fallback path: a cached response, a degraded answer, or a secondary provider.

Sources

In production

The discipline that separates a shipped system from a demo.

Fall back across providersFail over to another model when one degrades or rate-limits.

When the primary model provider returns sustained errors or degrades in quality, the system should automatically route to a secondary provider rather than returning errors to users. This requires the model call layer to be provider-agnostic: a unified client (LiteLLM is the most widely used) that maps provider-specific APIs to one interface and supports fallback chains in config.

The fallback provider needs to match the primary on the features you depend on: context length, tool calling, and structured output. Test the fallback path periodically so you know it works before you need it.

Degrade, don't crashA partial answer or a cached result beats an error page.

When a component fails, the system should return a useful partial response, a cached result, or a clear explanation, rather than an error page or a silent blank. A customer who gets a slightly stale answer or a 'I am temporarily limited' message has a better experience than one who gets a 500 error with no context.

Graceful degradation is designed in advance, not improvised during an incident. For each dependency, decide the fallback behavior before the dependency fails. Common fallbacks: serve a cached response for deterministic queries, route to a smaller faster model for less critical features, or disable the AI feature entirely while keeping the rest of the product functional.

Insurance · Voice

We shipped this layer in AVOX.

An insurance voice agent that handles policy, claim, and payment questions over the phone through MCP tools. Fast, fully auditable, and built to hold its response time under heavy call volume.

Time to respond
900ms
Read the case study

The vocabulary this layer assumes.

Put this whole roadmap on your team.

Every layer above is someone you can hire, production-proven and embedded in your team in days. Tell us what you are building and we will line up a shortlist.