liveBook · Manning

Chapter 13: Production LLM system design

What you will learn in chapter 13 of Machine Learning Platform Engineering

This chapter introduction explains why production LLM applications need disciplined prompt management, semantic evaluation, safety controls, and cost monitoring beyond traditional ML practices.

After this chapter you will be able to

What it builds on

Section by section

Introduction

This chapter introduction explains why production LLM applications need disciplined prompt management, semantic evaluation, safety controls, and cost monitoring beyond traditional ML practices.

Key terms: nondeterministic, probabilistic systems, assertion-based testing, semantic quality, DeepEval, prompt engineering workflows, version control, systematic testing, Langfuse, safety guardrails

13.1 Prompt engineering: Code for the generative AI era

Introduces prompts as production business logic that needs code-like discipline and managed versioning.

Key terms: business logic, prompts, versioning, testing, systematic optimization, Langfuse, prompt management, hardcoded strings, versionable assets, A/B tested

13.1.1 Treating prompts as critical infrastructure

This section shows why production system prompts need explicit roles, boundaries, response rules, and safety instructions by comparing a vague DakkaBot prompt with a production-ready one.

Key terms: system prompt, persona and role, constraints and guardrails, output format and style, context and task objectives, operational knowledge, version 1.0, helpful assistant, company documentation, scope creep

13.1.2 Langfuse prompt management for DakkaBot

This section shows how to move DakkaBot’s prompts into Langfuse and use them at runtime for versioned deployment, tracking, and graceful fallbacks.

Key terms: managed prompts, versioning, audit trail, labels, name, type, chat prompt, {{context}}, {{query}}, DakkaBotCore

13.1.3 Langfuse prompt management for production

The section presents Langfuse as production infrastructure for managing, deploying, testing, and reliably retrieving DakkaBot prompts without hardcoding them in application code.

Key terms: Langfuse, Content Management System (CMS), versioning, rollback, labels, production, staging, experimental, prompt versions, web interface

13.2 Testing LLM applications

This section explains why variable but valid LLM responses require evaluation beyond exact-output tests.

Key terms: deterministic software, exact matches, semantic correctness, factual accuracy, adherence to guidelines

13.2.1 Evaluation framework for LLM responses

This section shows how to test DakkaBot responses with DeepEval and G-Eval, using an LLM judge to assess security behavior and multiple quality dimensions rather than exact wording.

Key terms: DeepEval, G-Eval, LLM-as-Judge, Gemini, BLEU, ROUGE, DakkaBotCore, process_query, asyncio.run(), module-level DakkaBot instance

13.2.2 Safety and adversarial testing

The section explains why RAG assistants need adversarial security testing and shows how to use Promptfoo’s generated attacks and results to strengthen DakkaBot.

Key terms: RAG systems, prompt injection, knowledge boundary violations, DakkaBot, Promptfoo, promptfooconfig.yaml, promptfoo_provider.py, call_api, provider interface, plugins

13.3 Governance and safety in production

This section introduces the need for safety throughout a production LLM pipeline and for governance that balances innovation with risk.

Key terms: multilayered safety systems, pipeline, sensitive data, harmful content, compliance requirements, innovation velocity, risk management

13.3.1 Implementing safety guardrails

This section shows how to add layered, risk-appropriate safety checks to DakkaBot’s inputs, model processing, and outputs, then test responses for factual accuracy.

Key terms: input guards, processing controls, output guards, multilayered safety guardrails, Guardrails AI, CompetitorCheck, GuardrailsPII, on_fail, OnFailAction.EXCEPTION, OnFailAction.FIX

13.4 Cost optimization strategies

Introduces why production LLM systems need deliberate cost management by linking usage-based token charges to prompts, retrieved documents, and generated responses.

Key terms: token consumption, prompts, retrieved documents, generated responses, cost management

13.4.1 Understanding LLM economics

This section explains how token usage, model choice, deployment strategy, and traffic peaks shape the cost of a production LLM application.

Key terms: tokens, pay-per-token, input tokens, output tokens, model selection, GPT-4, Gemini Flash, specialized models, open-weight models, managed endpoints

13.4.2 Model selection strategy

This section shows how DakkaBot can choose an LLM at runtime according to query complexity to reduce costs, while managing the quality and operational risks of routing.

Key terms: CostOptimizedDakkaBotCore, router_llm, generation_llm, premium_llm, route_query(), process_query_optimized(), tiered routing, routing accuracy metrics, A/B test routing thresholds, multiple model endpoints

13.4.3 Caching strategies

This section explains how context and semantic caching reduce repeated LLM work, when their savings outweigh their costs, and how RedisVL can implement semantic caching.

Key terms: context caching, cached context, cache invalidation, semantic caching, embeddings, similarity threshold, semantic drift, time-to-live (TTL), RedisVL, Redis hash

13.4.4 Prompt optimization for efficiency

This section shows how to reduce LLM prompt token costs without sacrificing response quality, safety, or consistent behavior.

Key terms: token consumption, operational costs, prompt efficiency, identity compression, instruction consolidation, format simplification, redundancy elimination, Q:/A:, A/B testing, evaluation criteria

13.4.5 Production cost monitoring

This section explains how to monitor production LLM costs, catch budget risks, and use Langfuse to judge whether spending delivers value.

Key terms: production cost monitoring, real-time insights, spending patterns, aggregate spending, per-query costs, expensive outliers, cost alerts, budget thresholds, Langfuse, token usage

13.4.6 From traditional ML to LLMOps

This section explains how LLMOps builds on established MLOps engineering practices while adapting them to the distinctive demands of production LLM systems.

Key terms: LLMOps, MLOps, automation, observability, systematic testing, continuous improvement, prompt engineering as code, version control, deployment pipelines, retrieval

13.5 Summary

The chapter summary brings together the evaluation, prompt, safety, cost, and infrastructure practices needed to run LLM applications in production.

Concepts explained in this chapter

← Chapter 12: Designing LLM-powered systems

These guides are generated from the text of Manning books by Manning's knowledge graph and link to the sections they draw on. The full books are available on liveBook and at manning.com.