Every team is adding an LLM to their product right now. Far fewer teams have thought about what happens after the demo works and real users start typing things the model was never tested on. This post is about the gap between an AI feature that impresses in a prototype and one that holds up in production.

Start With The Failure Mode

Before writing any prompt, answer one question: what should the product do when the model is wrong, slow, or unavailable? There are only a few honest answers.

  • Return an error and let the user retry.
  • Show the output with a confidence signal and let the user decide.
  • Fall back to a deterministic path, such as a template or a search result.
  • Escalate to a human.

Pick one per feature and write it down. Teams that skip this step end up inventing a fallback under pressure at launch, and it usually shows.

Treat The Prompt As Code

A prompt that lives in a Slack message is not maintainable. Put it in a file, version it, and treat changes to it like changes to any other logic. A small diff in wording can shift output quality significantly, so you want a history you can diff and roll back.

# app/prompts/support_summary.txt.erb Summarize the customer message below in two sentences. Do not invent details that are not present. If the message is empty, return an empty string. Message: <%= message %> 

Loading prompts from files also makes it easy to run the same prompt across environments and to test variations without a deploy that touches application code.

Validate The Output, Do Not Trust It

LLMs return strings. Your application expects structured data. The bridge between those two is validation. If you ask for JSON, parse it and check the shape before you use it. If parsing fails, that is a normal case, not an exception to swallow.

result = JSON.parse(response_body) raise InvalidModelOutput unless result.key?("summary") && result["summary"].is_a?(String) 

Wrap the call so that invalid output triggers your defined fallback instead of a 500. This one habit removes a large class of production incidents.

Keep Latency Visible

Model calls are slow compared to the rest of your request path. Put a timeout on every call and log the duration. If a feature depends on an LLM response, decide whether it belongs in the request cycle at all or whether it should run as a background job. Summaries, tagging, and enrichment usually belong in a job. Anything the user is waiting on needs a tight timeout and a clear loading state.

Cost Is An Engineering Concern

Token usage adds up quietly. Log the token count per request alongside the user and feature. When a feature gets expensive you want to know which users or which inputs drove it, and you want that data before the invoice surprises you. Caching identical or near-identical requests is often the cheapest win available.

Test With Real Inputs

Build a small set of real inputs from your own product, including the messy ones, and run them against every prompt change. This does not need to be an elaborate harness. A script that feeds a dozen representative cases through the prompt and prints the output is enough to catch regressions before users do.

Wrap Up

The hard part of AI features is not the first working demo. It is the error handling, the validation, the timeouts, and the cost visibility that let the feature run unattended for months. Build those from the start and the rest gets much easier.

If you are adding AI to an existing product and want help getting it production-ready, we build this kind of thing at developerz.ai.