Mahamudul Hasan Rubel
HomeAboutProjectsSkillsExperienceBlogPhotosContact
Mahamudul Hasan Rubel

Senior Software Engineer crafting high-performance web applications and SaaS platforms.

Navigation

  • Home
  • About
  • Projects
  • Skills
  • Experience
  • Blog
  • Photos
  • Contact

Get in Touch

Available for senior/lead roles and consulting.

bd.mhrubel@gmail.comHire Me

© 2026 Mahamudul Hasan Rubel. All rights reserved.

Built with using Next.js 16 & Tailwind v4

Back to Blog
AI/MLJune 20, 20264 min read

Prompt patterns that survive contact with production

Prompt patterns that survive contact with production require more than just clever phrasing. Learn to build resilient AI workflows that handle real-world data.

LLMPrompt EngineeringAIPythonProduction EngineeringRAG
Drone capture of vibrant rice fields in West Java, showcasing natural patterns and greenery.

Last month, our team spent three days debugging a production failure where our summarization agent suddenly started outputting JSON with trailing markdown backticks, breaking our downstream ingest pipeline. We thought we had a "perfect" system prompt, but we hadn't accounted for the model's drift during a minor provider version update.

Building reliable AI features isn't about writing the most creative prompt; it’s about treating your prompt engineering as a form of software testing. If you’re tired of your application failing because an LLM decided to be "helpful" instead of "precise," these patterns will help you stabilize your production environment.

Why Prompt Patterns That Survive Contact With Production Matter

When you move from a playground environment to a live application, the biggest enemy isn't the model's intelligence—it's its unpredictability. You need to treat your LLM calls like any other API dependency. If you aren't enforcing schema constraints, you’re just one "As an AI language model..." response away from a production incident.

I’ve found that the most resilient systems don't rely on a single, massive "God prompt." Instead, they decompose the task into smaller, verifiable chunks. If you're struggling to get consistent results, you might be asking your model to do too much at once.

The Decomposition Pattern

We first tried to build a RAG pipeline that would fetch context, summarize it, and extract structured metadata in a single call. It worked about 60% of the time. When the context got noisy, the model would hallucinate fields or ignore the formatting instructions entirely.

We refactored this by building a small RAG pipeline end to end in Python where the retrieval logic and the extraction logic are strictly separated.

  1. The Retrieval Agent: Only cares about finding relevant chunks.
  2. The Extraction Agent: Only cares about turning those chunks into a strict schema.

By separating these concerns, we saw our error rate drop from roughly 15% down to about 2% over a two-week period. If you're building a system that requires high fidelity, stop trying to force the LLM to be a multi-modal Swiss Army knife.

Enforcing Structured Outputs

Stacked professional audio video equipment with multiple connectors for recording studio settings.

One of the most critical prompt patterns that survive contact with production is the move away from raw text generation toward structured output. In our latest stack, we use Pydantic models to define exactly what the LLM should return.

If you aren't already doing this, getting reliable structured output from an LLM in production is the single highest-leverage change you can make. Here is a simple example of how we handle this using Python and a schema-enforcement library:

PYTHON
from pydantic import BaseModel, Field

class ExtractionSchema(BaseModel):
    summary: str = Field(description="A concise 2-sentence summary.")
    sentiment: str = Field(description="Must be one of: positive, negative, neutral.")

# We pass this schema to the LLM's tool-calling or JSON-mode API
# rather than asking for a JSON block in the prompt text.

By leveraging tool-calling or constrained output modes (like OpenAI's json_schema parameter), you move the burden of formatting from the model's "creativity" to the API's deterministic parser.

Defensive Prompting: The "Negative Constraint" Trap

Early on, we relied heavily on "Do not do X" instructions. I’ve learned that models are notoriously bad at processing negative constraints. If you tell an LLM "Do not include the user's name in the response," it often treats that as a suggestion to focus on the name.

Instead of negative constraints, provide positive examples. Use a few-shot approach where the example output explicitly shows the desired behavior. If you want a specific style, include a "golden" output in your system prompt:

  • Bad: "Do not be verbose."
  • Good: "Response format: [Concise Answer]. Keep under 50 words."

Handling Latency and Reliability

Even with the best prompts, LLMs are slow compared to traditional database queries. If you’re running these in a request-response cycle, you’ll likely run into UX issues. We’ve found success in running background workers with systemd for production reliability to process LLM tasks asynchronously.

By offloading the generation to a background worker, we can retry failed attempts with exponential backoff without blocking the user interface. It also lets us implement a queue-based system where we can prioritize jobs based on user tier or urgency.

What I’m Still Figuring Out

Silhouette of a woman standing at an open window in Jatni, India during daytime.

Despite these patterns, I’m still not 100% confident in how to handle model drift over long durations. Even when your prompts are pinned to a specific version of a model, the underlying weights can sometimes shift slightly, leading to subtle changes in output behavior.

My current strategy is to maintain a small "eval set"—a list of 20-30 inputs and their expected outputs—that we run against every new prompt change. If the new prompt fails any of these, we don't deploy. It’s not perfect, but it’s saved us from several late-night rollbacks.

If you're building with LLMs, don't chase the "perfect" prompt. Chase the most stable, repeatable process. Start small, enforce your schemas, and for heaven's sake, move your heavy lifting to background tasks.

Back to Blog

Similar Posts

A focused developer writing code on a laptop in an indoor workspace.
AI/MLJune 20, 20264 min read

Building a small RAG pipeline end to end in Python

Building a small RAG pipeline is the fastest way to ground LLMs in your data. Learn the end-to-end process of indexing, retrieval, and generation.

Read more
Close-up view of a vintage tape recorder showcasing VU meters and control knobs.
AI/ML
June 20, 2026
4 min read

Getting reliable structured output from an LLM in production

Getting reliable structured output from an LLM is the difference between a prototype and a product. Learn how to enforce JSON schemas effectively.

Read more
Close-up of an illuminated audio mixer panel in a recording studio, showcasing various controls and switches.
AI/MLJune 20, 20264 min read

Controlling LLM cost and latency: A Practical Production Guide

Controlling LLM cost and latency is the biggest hurdle in production. Learn how to optimize token usage and response times to keep your AI features fast.

Read more