Designing Production-Grade LLM Applications¶
An architecture approach to model decisions, context, security, evaluation, and operation
A useful LLM prototype can be built with an API call and a prompt. Turning it into a reliable enterprise application requires considerably more design. The model is one component; the application must also decide which work to accept, where its information comes from, how requests are coordinated, what a user may access, and how to tell whether an answer is trustworthy.
This deep dive presents a systematic approach to designing production-grade LLM applications, starting with application requirements rather than a particular model or cloud service.
We'll explore seven architectural areas:
- Production GenAI System Architecture — workloads, logical responsibilities, integration boundaries, and deployment choices.
- Foundation Model Selection and Inference Architecture — model evaluation, routing, hosting, and serving strategies.
- Prompt Engineering, Context Engineering, and Generation — application instructions, evidence, conversation state, and output contracts.
- Model Evaluation — quality measurement, acceptance criteria, and release validation.
- GenAI Security — access controls, data protection, guardrails, and operational boundaries.
- Production Optimization — performance, scaling, caching, cost, resilience, and observability.
- Architecture Decisions and Review — consolidated decisions, alternatives, trade-offs, and review criteria.
The reference scenario is an Enterprise IT Operations Assistant supporting employees, on-call engineers, and operations managers. It's an illustrative design, not a claimed production deployment or performance benchmark. We use it to test decisions, not to dictate the architecture. The companion Enterprise RAG deep dive examines document ingestion, retrieval, freshness, and evidence assembly in detail.
1. Production GenAI system architecture¶
Define the workloads before choosing components¶
The first design task is to identify what the application must do and how the workloads differ. A single AI product may contain interactive requests, investigative work, and background processing. Those demands should shape the architecture before any model or framework is selected.
Consider three requests to our operations assistant:
- An employee asks, “How do I request temporary production access?” The answer should be fast, cite the applicable policy, and never imply that asking the assistant grants access.
- An on-call engineer asks, “What changed before the payment API's latency increased?” This requires correlating incident records, deployments, telemetry, and runbooks. Findings must distinguish observation from hypothesis; any operational change needs separate authorization and approval.
- An operations manager requests a weekly report on recurring incidents. Results must be reproducible and complete, but a few minutes of background processing may be acceptable.
| Workload | Execution pattern | Primary design concern |
|---|---|---|
| Employee self-service | Interactive, evidence-grounded Q&A | Response time, authorization, citations |
| Incident investigation | Interactive, potentially multi-step analysis | Multiple data sources, reasoning quality, read-only access, human judgment |
| Operations reporting | Asynchronous job processing | Throughput, checkpoints, repeatability, cost |
These paths can reuse the same model-access and governance capabilities, but different latency budgets, safety expectations, and scaling profiles call for distinct request contracts. A background report should not occupy the interactive request queue; a self-service query should not automatically receive permission to call operational tools.
Define the logical architecture¶
Once the workloads are clear, we can organize the system into responsibilities with explicit interfaces. The following four layers form a logical architecture: they describe what must be owned and coordinated, not how many services to deploy.
Experience and serving is the application-facing boundary. It owns:
- User and API entry points, authentication, request validation, and rate limits.
- Streaming, cancellation, request identifiers, and user-visible errors.
- Session access and the response contract exposed to clients.
Orchestration and application logic coordinates a request. It owns:
- Task identification and application-controlled routing.
- Policy checks and approved data, model, and tool selection.
- Prompt and context assembly, step sequencing, retries, and response validation.
Enterprise data and state contains the information and state the application uses:
- Versioned knowledge and search indexes; live operational data through constrained APIs.
- Conversation sessions, job status, document permissions, provenance, and audit references.
- Different freshness and retention rules for each source, rather than one generic “memory.”
Models and inference provide trained-model computation:
- Text generation and reasoning, embeddings, reranking, and classification where needed.
- Model invocation and capacity through managed APIs or self-hosted inference.
- Model capabilities—not authority to inspect systems or execute business actions.
Security, evaluation, observability, and cost control apply across all four layers. They aren't optional post-processing stages.
Logical layers versus deployment architecture¶
An architecture diagram describes what the system must do. A deployment design describes where those responsibilities run.
For an initial implementation, one modular application might contain the serving API, router, prompt builder, and model adapter. The retrieval store and session database are external dependencies. Later, a dedicated report-worker pool might be extracted because its queue-driven throughput, release cycle, and failure handling differ from interactive chat.
This is a deliberate trade-off:
| Design | When it fits | Cost of the choice |
|---|---|---|
| Modular application | Early-stage product, shared team, moderate scale | Modules share process and deployment failure boundaries |
| Independently deployed services | Different scaling, trust, release, or ownership needs | Network calls, contracts, observability, and operating overhead |
Don't turn every box in a logical diagram into a service. Introduce deployment boundaries only when a requirement justifies the added complexity.
Interfaces and data contracts¶
The serving layer should pass a request with authenticated identity, task, session, and correlation ID—not an arbitrary “model ID” supplied by the caller. Retrieval should return evidence with source IDs, version or timestamp, and applicable access metadata. The generation adapter should receive an approved model choice, prompt version, context budget, and expected output form.
For incident analysis, make the output contract distinguish observed fact, hypothesis, recommended action, and executed action. An LLM's suggestion that a rollback might help is not evidence that a rollback was authorized or performed.
Enterprise knowledge and live operational data¶
A model cannot diagnose an incident from information it has never received. Before designing prompts, decide which information is reference knowledge, which is live operational state, and who is allowed to access each source.
- RAG retrieves approved policies, procedures, and historical knowledge. It is well suited to frequently changing reference material.
- Constrained read APIs obtain current deployment status, service metrics, active incidents, or ticket records. A model's training data is not an operational source of truth.
- Model customization may help with specialized output behavior or terminology after prompting and evaluation. Fine-tuning or LoRA does not replace real-time retrieval, authorization, or up-to-date operational records.
An incident copilot may use RAG and live read-only APIs. Allowing it to propose a change is still different from giving it tools to execute that change. Detailed autonomous-agent orchestration belongs in a separate Deep Dive.
Enterprise integration: preserve contracts and authority¶
Connecting an LLM application to production systems is an integration problem before it becomes a model problem. The orchestrator should request approved information through defined adapters, not generate unrestricted SQL, compose arbitrary monitoring queries, or receive blanket access to operational accounts.
For the latency-investigation workflow, use narrow read interfaces for incident history, deployment changes, and telemetry. Each adapter owns the external API contract, pagination, limits, credential handling, and normalization into an evidence record. For example, a returned observation should carry a source identifier, observation time, scope, and access decision, not just a text snippet the model could repeat without qualification.
Authentication and authorization: The application authenticates the engineer, while each downstream adapter ensures access is limited to permitted resources. Use a service identity with appropriate permissions or delegated user access where supported. An IAM role does not automatically provide document-level authorization. Any future write operations must have separate, explicitly approved permissions.
Concurrent requests and failure handling: Independent API calls can run in parallel, but each must have a timeout and a defined failure response. For example, if deployment data is available but the monitoring API times out, the copilot can report confirmed deployment changes but must clearly state that the root cause remains undetermined.
Integration flexibility: Keeping external systems behind adapters allows ITSM or monitoring vendors to be replaced without changing the core model orchestration logic.
2. Foundation model selection and inference architecture¶
Foundation model selection: use requirements and evidence¶
Model selection is a requirements and evidence decision. The goal is to find a model that meets the task's quality and security requirements, then optimize latency and cost within those limits. Neither the largest model nor the cheapest model is automatically the right choice.
First, remember that an application may invoke several model types:
| Stage | Model role | Result |
|---|---|---|
| Ingestion and query preparation | Embedding model | Vectors in a compatible embedding space |
| Retrieval refinement | Reranking model, if justified | Ordered evidence candidates |
| Query processing | Classification or generative model, if required | Intent, rewritten query, or task selection |
| Response generation | Generative foundation model | Answer, summary, or structured analysis |
Our model-selection discussion below focuses on the generation model, while the same evaluation discipline also applies to embedding and reranking models. Changing an embedding model can require re-embedding and reindexing; it is not a drop-in generation-model swap.
A practical decision framework¶
Before comparing model names, separate hard requirements from optimization goals.
- Define the workload. Specify task, data sensitivity, required output, context length, interactive or batch behavior, and typical concurrency.
- Set minimum thresholds. Establish task-specific quality and safety acceptance criteria, required feature support, approved processing locations, and latency or budget limits.
- Compare viable candidates. Evaluate models on a representative dataset; measure quality, latency, token consumption, and total serving cost under comparable configurations.
- Choose within the feasible set. Optimize the most important variable without violating the hard thresholds. Document the trade-offs and the fallback policy.
- Measure and revisit. Repeat evaluation when the model, prompt, workload, context strategy, or provider behavior changes.
The familiar quality–latency–cost triangle is a useful conversation starter, not a guarantee that improving one dimension always worsens another. Security, correctness thresholds, data residency, and required capabilities should normally act as constraints, not points traded away for lower cost.
For our assistant, model choices might look like this:
| Workload | Quality gate | Optimization priority | Provisional model approach |
|---|---|---|---|
| Employee Q&A | Correct authorized policy, source support, safe abstention | Interactive latency and cost | Smaller/faster candidate if it passes evaluation |
| Incident investigation | Accurate evidence interpretation and uncertainty | Reasoning quality | Stronger candidate where tests prove the benefit |
| Weekly reporting | Correct aggregation, structured output, completeness | Cost per completed job | Cost-efficient model with batch processing |
These are candidate strategies, not benchmark results or vendor recommendations. A smaller model that misses production-policy exceptions is not a cost optimization; it fails the acceptance gate.
Example: choosing a model for incident investigation¶
Suppose the incident workflow requires at least 90% SME acceptance on a representative test set and p95 completion within six seconds. Compare two approved generation models using the same evidence packages and response format:
| Evaluation criterion | Fast model | Reasoning model | Acceptance gate |
|---|---|---|---|
| SME-accepted analyses | 82% | 94% | ≥90% |
| p95 end-to-end latency | 2.0 seconds | 5.0 seconds | ≤6 seconds |
| Relative inference cost | 1× | 3× | Within approved budget |
| Decision | Fails quality gate | Eligible | All hard gates must pass |
These numbers are hypothetical examples of the decision process, not measured model benchmarks. The stronger model is the candidate despite its higher cost. Before approving it, inspect which cases failed: a 94% overall score could still conceal unacceptable errors in privileged-access or production-change scenarios. Then repeat the comparison under realistic concurrency and token budgets. The weighted score helps compare feasible candidates; it must not compensate for a failed hard requirement.
Model routing: an application decision¶
Once the models have been evaluated and approved, the next decision is how to route different workloads to the appropriate model at runtime.
Model selection is primarily a design-time decision. Model routing is a runtime decision that operates within the approved models and their quality, security, latency, and cost constraints.
Model routing strategies¶
| Strategy | How it works | Trade-off |
|---|---|---|
| Deterministic routing | Selects a model using predefined rules, such as task type, workload, or user tier | Simple, predictable, and auditable; less flexible for ambiguous requests |
| AI-based routing | Uses a lightweight classifier or model to identify task type or complexity and select an appropriate model | More adaptive; introduces classification errors, additional latency, and cost |
| Hybrid routing | Applies deterministic rules first and uses AI-based classification for ambiguous requests | Balances predictability and flexibility; adds routing logic and evaluation complexity |
Applying the decision¶
For our Enterprise IT Operations Assistant, deterministic routing is a reasonable starting point because the application already distinguishes three workloads:
- Employee Q&A: Route to an approved, cost-efficient model optimized for fast, grounded responses.
- Incident investigation: Route to a model that meets stronger reasoning and evidence-analysis requirements.
- Operations reporting: Route to an approved model and asynchronous inference workflow optimized for throughput and cost.
As the platform evolves, a hybrid approach may become useful when user requests cannot be reliably classified through existing application context.
Regardless of the strategy, routing must remain server-controlled and operate within approved model configurations.
Fallback is a separate decision. Before redirecting a failed request, verify that the alternative model meets the workload's quality requirements, context limits, structured-output needs, security policies, and capacity budget. Spare inference capacity does not automatically make a model an acceptable fallback.
The routing strategy should evolve based on measured accuracy, latency, cost, and operational complexity—not simply the availability of more models.
Inference: execution versus serving¶
Model capability and the infrastructure used to run it are related but separate choices. Keep these three terms distinct:
- Model selection: Which model is capable of the task?
- Inference execution: Running a trained model on supplied input to generate tokens, embeddings, rankings, or classifications.
- Inference serving: Where and how that computation is provisioned, scheduled, exposed, and scaled.
These decisions interact, but none is a synonym for the others. An application model router chooses an approved model for a business task. An inference profile may govern permitted infrastructure/Region routing for that selected model. A profile does not replace business-task classification.
Hosting and serving options¶
| Choice | Architectural fit | Responsibilities and trade-offs |
|---|---|---|
| Managed model APIs | Fast adoption and variable workloads | Provider limits, data processing terms, availability, invocation budgets |
| Self-hosted model serving | Specific runtime, data-path, customization, or sustained-utilization needs | GPU sizing, serving software, replicas, patching, security, full operating cost |
| Hybrid deployment | Different workloads have materially different constraints | More governance, routing, version testing, and observability |
A self-hosted model is neither inherently cheaper nor automatically compliant. The answer depends on utilization, redundancy, engineering overhead, model performance, contracts, data flows, and applicable controls.
Amazon Bedrock example. The same selected model can have different supported serving arrangements:
- On-demand: Invoke without purchasing dedicated throughput; respect model-specific request/token quotas.
- System-defined cross-Region inference profiles: Route invocation for a particular model among supported destination Regions. Check the actual destinations from each source Region using
GetInferenceProfile. An SCP or IAM deny covering a required destination can cause the invocation to fail; a geographic prefix alone is not sufficient evidence of the allowed processing path. - Application inference profiles: Associate supported foundation models or system-defined profiles with application-level usage and cost tracking. They are not the application router that classifies business requests.
- Provisioned Throughput: Purchase reserved inference capacity for supported configurations when utilization and quality-of-service needs justify the commitment. It is a different capacity approach from inference-profile-based cross-Region routing.
- Batch inference: Submit supported offline workloads asynchronously rather than holding open interactive requests.
Converse and ConverseStream provide a common conversational interface for supported models; the applicable model ID or inference profile identifies the serving target. The application routes business workloads; Bedrock manages the selected inference serving path. Support, limits, caching, and pricing vary by model, Region, and API. See the official inference profile documentation, destination Region guidance, and provisioned throughput guidance.
3. Prompt engineering, context engineering, and generation¶
Prompt engineering: defining application behavior and task contracts¶
In a production LLM application, prompt engineering is an application-design responsibility, not just a skill expected from end users.
Users submit questions or instructions, but the application must establish how the model should interpret those requests, use available information, and produce reliable, consistent responses.
Without application-defined instructions, two engineers asking similar incident-investigation questions might receive completely different responses. One answer could identify a recent deployment as the confirmed root cause, while another correctly treats it as a possible cause requiring further investigation.
Prompt engineering addresses this problem by defining a consistent task contract between the application and the model.
System instructions vs. user prompts¶
An LLM request typically combines several inputs, each with a different responsibility:
| Input | Responsibility | Example |
|---|---|---|
| System instructions | Application-controlled role, expected behavior, and governing rules | Analyze incidents using evidence; distinguish facts from hypotheses |
| User prompt | The question or task submitted by the user | Why did payment API latency increase after yesterday's deployment? |
| Context | Relevant information assembled by the application | Logs, metrics, deployment history, incident records |
At runtime, the application selects an appropriate prompt template, combines it with the user's request and relevant context, and invokes the selected model.
This separation allows the same application to support different workloads while maintaining consistent behavior.
What should a prompt contract define?¶
Depending on the workload, an application-controlled prompt template may establish:
- Role and task: What the model is expected to accomplish.
- Instructions and constraints: How to interpret evidence, distinguish facts from assumptions, and avoid unsupported conclusions.
- Output requirements: Expected structure, level of detail, citations, or machine-readable format.
- Uncertainty handling: How to respond when evidence is missing, incomplete, or contradictory.
- Behavioral boundaries: What the model may recommend versus what requires external authorization or human approval.
Example: Incident investigation¶
Consider an engineer asking the Enterprise IT Operations Assistant to investigate an API latency spike following a deployment.
The application could use the following simplified system prompt template, defined and maintained by the engineering team:
Role: Enterprise IT Incident Analysis Assistant
Task:
Analyze incidents using the supplied operational evidence.
Instructions:
- Separate observed facts from possible causes.
- Examine relationships between deployments,
logs, metrics, and incident timelines.
- Do not present correlation as confirmed causation.
- Cite supporting evidence for significant findings.
- Highlight missing or conflicting information.
- If the root cause cannot be established,
recommend further investigation.
Output:
1. Incident summary
2. Observed evidence
3. Possible causes and supporting evidence
4. Recommended next steps
Do not claim to have executed operational changes.
The user's request might simply be:
Investigate the payment API latency increase following yesterday's deployment.
The application retrieves authorized operational evidence, assembles the context, and sends these inputs to the selected model.
The prompt template guides the model toward a consistent, evidence-based analysis without requiring users to specify the investigation methodology every time.
Architectural considerations¶
Prompt templates are versioned application artifacts. They should be managed and evaluated alongside model configurations and retrieval strategies. A prompt change can affect answer quality, output consistency, token consumption, and latency.
Keep trusted application instructions separate from user input and retrieved evidence. Logs, runbooks, and tool responses are data, not instructions permitted to override application policies.
Most importantly, prompt engineering influences model behavior but does not enforce security or business rules. A prompt may prohibit unauthorized changes, but IAM, application authorization, and controlled tool APIs must enforce those restrictions independently.
The goal is not to eliminate every possible model error through increasingly elaborate prompts. It is to establish clear, testable behavior that can be improved through evaluation and maintained as the application evolves.
Context engineering: assemble the right evidence¶
Even a well-designed prompt cannot produce a reliable answer when the model receives incomplete, outdated, or irrelevant information.
Context engineering determines what information the model receives for a particular request. Its purpose is to provide sufficient, relevant, and authorized evidence without overwhelming the model with unnecessary content.
It goes beyond vector search or simply attaching retrieved documents to a prompt.
A practical context assembly process involves:
- Establish the request and authority. Identify the task, user identity, and permitted data scope before accessing protected sources.
- Retrieve relevant evidence. Combine appropriate knowledge sources, such as runbooks, with current operational facts obtained through approved read APIs.
- Validate the evidence. Check authorization, source reliability, timestamps, document versions, relevance, and conflicting information.
- Optimize the context. Remove duplication, preserve important exceptions, and prioritize the most useful evidence within the available token budget.
- Preserve provenance. Include source identifiers and citation references so generated claims can be traced back to their supporting evidence.
Applying this to our incident investigation:
For an API latency spike, the assembled context might include:
- The deployment timestamp and associated change record.
- Relevant latency metrics, traces, and error patterns.
- The applicable troubleshooting runbook.
- Previous incident findings, if relevant and authorized.
The model does not need hundreds of raw log lines or every document containing the word latency.
The objective is useful evidence, not maximum context volume. Excessive context increases token consumption and can obscure important signals or introduce conflicting information.
Context window and conversation state¶
Every model has a finite context window, which limits the tokens available for processing the request and, depending on the model and API, generating its response.
The application must manage this budget across system instructions, user input, conversation history, retrieved evidence, tool definitions where applicable, and the required output allowance.
A larger context window provides more capacity, but it does not eliminate the need to prioritize relevant information.
Conversation state introduces a separate architectural decision.
The model does not automatically maintain persistent application memory across independent inference requests. If a conversation requires continuity, the application must manage the relevant history or state and supply what is needed for subsequent requests.
Consider these approaches:
- Recent conversation turns: Retain a bounded number of messages for immediate continuity.
- Conversation summaries: Compress older interactions while preserving relevant decisions and unresolved questions.
- Structured state: Store important session attributes or workflow progress independently of the conversation transcript.
For horizontally scaled applications, state that must survive replica changes or restarts should be maintained outside individual application instances, using an appropriate shared or durable store.
Define ownership, retention, expiration, tenant isolation, and access controls for that state.
Conversation history is context, not authoritative operational evidence. For example, an earlier assistant message stating that a rollback was approved must not replace verification against the actual change-management or deployment system.
Generation and output contracts¶
After assembling the prompt and relevant context, the model generates a response. But generating text is not the same as producing a response the application can safely use.
The architectural responsibility is to define what the model should return and how the application validates it before consumption.
Define output contracts by workload¶
Different workloads require different response formats and validation rules:
- Employee Q&A: A concise, grounded answer with verifiable source references.
- Incident investigation: Structured findings containing observations, possible causes, supporting evidence, uncertainties, and recommended actions.
- Operations reporting: Schema-compliant summaries and classifications, with validated aggregates and job-completion status.
For machine-consumed responses, an output contract may specify required fields, data types, allowed values, and optional attributes.
Validate generated output¶
Where supported, constrained structured-output features can enforce a JSON Schema. However, a structurally valid response is not necessarily factually correct or operationally safe.
The application must validate:
- Structure: Does the response conform to the expected schema?
- Business rules: Are identifiers, values, and proposed actions valid?
- Evidence: Are important claims supported by authorized sources?
- Consistency: Are timestamps, incident states, and referenced entities consistent with authoritative systems?
For example, our incident assistant might produce a valid JSON response identifying a deployment as the root cause. The application should not treat that diagnosis as confirmed merely because the output satisfies its schema. Evidence and business-rule checks remain necessary.
AWS implementation consideration¶
Amazon Bedrock supports structured outputs for compatible models and inference APIs, but feature combinations have limitations.
For example, Bedrock documents that structured outputs and built-in citations are incompatible for supported Anthropic model configurations; enabling both can result in an API error.
If incident analysis requires both structured findings and source references:
- Verify the selected model and API support the required features.
- Where appropriate, include source identifiers as application-managed output fields.
- Validate those identifiers against the authorized evidence supplied to the model.
- Reject or qualify responses that fail the application's acceptance criteria.
See Amazon Bedrock — Structured Outputs.
The key distinction: The model generates a candidate response; the application determines whether that response satisfies the contract and can be released or used by downstream systems.
4. Model evaluation¶
Model and system evaluation¶
Evaluation turns architecture assumptions into evidence. A plausible demonstration tells us little about whether a model consistently interprets policy exceptions, cites the right source, or declines questions it cannot support.
Evaluate at three levels:
| Level | What to test | Example failure |
|---|---|---|
| Model | Instruction following, task reasoning, structured output, cost, latency | Model misunderstands a change-freeze exception |
| Retrieval and context | Evidence recall, source validity, version, completeness | Current policy was never placed in context |
| End-to-end application | Correctness, groundedness, citations, abstention, authorization, workflow behavior | Model cites an outdated runbook or asserts an unverified cause |
Correctness and groundedness differ. An answer can faithfully quote a superseded policy and still be wrong about the current rule. An accurate-sounding incident hypothesis can also be unsupported by available evidence.
Use metrics that isolate the source of failure:
- Retrieval: Recall@K asks whether the required evidence entered the candidate set; Precision@K and ranking metrics help detect irrelevant or poorly ordered candidates. For multi-part questions, also test evidence coverage.
- Generation: Check factual correctness against a verified answer, groundedness against the supplied evidence, and whether each citation actually supports its claim.
- Answerability: Measure appropriate abstention and handling of missing or contradictory facts—not just the percentage of requests that receive an answer.
- Security and contracts: Test unauthorized retrieval, prompt-injection/tool violations, schema validity, and approval boundaries as hard pass/fail conditions.
Golden datasets and evaluation methods¶
A golden dataset is a curated collection of representative test cases with known expected outcomes. It provides a repeatable baseline for measuring whether changes to models, prompts, retrieval, or application logic improve quality or introduce regressions.
For our Enterprise IT Operations Assistant, the dataset should represent:
- Routine questions: Employee Q&A with verified answers and supporting sources.
- Incident investigations: Multi-source evidence requiring correlation and reasoning.
- Incomplete or conflicting evidence: Cases where the expected behavior is to qualify the answer or abstain.
- Outdated information: Documents or operational records that should not override current authoritative sources.
- Security scenarios: Unauthorized access attempts, prompt injection, and prohibited tool operations.
- Structured outputs: Incident findings and reporting results that must meet defined schemas and business rules.
Each test case should document the input, relevant evidence, expected answer or behavior, permitted access scope, and acceptance criteria.
Evaluation should combine:
- Deterministic checks: Schema validation, required fields, citations, permissions, and business-rule compliance.
- Automated model-based evaluation: LLM-as-a-Judge scoring for qualities such as relevance, correctness, and groundedness.
- Human review: Engineering and security subject-matter experts validating complex, ambiguous, or high-impact outcomes.
LLM-as-a-Judge can scale evaluation, but its scores should be calibrated against human-reviewed examples rather than treated as definitive ground truth.
Evaluation in the release lifecycle¶
Evaluation is not a one-time activity performed when selecting a foundation model. It should be part of the application's change and release process.
A practical release sequence is:
- Establish a baseline: Record the current production configuration and its quality, latency, security, and cost measurements.
- Introduce a candidate: Identify the model, prompt, retrieval, or guardrail configuration being changed.
- Run offline evaluation: Compare the candidate against the golden dataset and predefined acceptance thresholds.
- Roll out gradually: Release to a controlled group or limited traffic after critical checks pass.
- Monitor production behavior: Track quality signals, failures, latency, cost, and user feedback.
- Promote or roll back: Expand adoption when results are acceptable; otherwise revert or refine the candidate.
The key principle is to treat model and prompt changes with the same release discipline as application changes, while also evaluating their probabilistic behavior.
A configuration that performs well in offline tests still needs production monitoring because real requests, data distributions, and usage patterns may differ.
AWS offers Bedrock model evaluation and RAG evaluation workflows, including retrieval-only and retrieve-and-generate assessments. These provide useful assessment infrastructure, but enterprise-specific reference answers, severity-weighted test cases, and authorization tests remain ours to define.
5. GenAI Security¶
Production LLM applications introduce additional security considerations because they process user instructions, retrieve enterprise data, and may interact with external systems.
Security must be enforced by the application and its infrastructure—not delegated to the foundation model.
Security controls and design considerations¶
| Security area | Architectural consideration |
|---|---|
| Authentication | Authenticate users and API clients through an approved identity provider. |
| Authorization | Enforce access to documents, data sources, and operations based on the caller's permissions. |
| Prompt injection protection | Treat user-supplied and retrieved content as untrusted; protect application instructions and tool execution. |
| Tool and action security | Restrict tool permissions, enforce least privilege, and require approvals for sensitive operations. |
| Data protection | Protect sensitive inputs, outputs, conversation history, and logs using appropriate encryption, isolation, and retention policies. |
| Guardrails | Apply content safeguards, sensitive-information filtering, and applicable output policies. |
| Audit and monitoring | Record relevant access, model invocations, tool actions, approvals, and security events without unnecessarily exposing sensitive data. |
Applying security controls on AWS¶
For an Enterprise IT Operations Assistant deployed on AWS:
- Identity and access: Integrate with an enterprise identity provider and enforce application authorization; use IAM roles and policies for AWS resource access.
- Data security: Use AWS KMS-backed encryption where appropriate, private connectivity, and controlled access to enterprise knowledge sources.
- Model safeguards: Configure Amazon Bedrock Guardrails for supported content filters, denied topics, and sensitive-information controls.
- Monitoring and audit: Use AWS CloudTrail and application-level observability to capture relevant operational and security events.
Guardrails complement security controls; they do not replace authentication, authorization, IAM, or business-policy enforcement.
For example, Bedrock Knowledge Bases RetrieveAndGenerate guardrails do not independently screen retrieved reference chunks. Applications must enforce document permissions and any required source-content checks separately.
For our incident investigation assistant, begin with read-only access to approved operational systems. Actions such as restarting services or initiating rollbacks should require separately authorized and auditable execution paths.
The detailed design of those action workflows belongs in a dedicated agentic AI architecture discussion.
6. Production optimization¶
Performance and latency¶
Performance optimization should begin by identifying where time is spent, rather than assuming the LLM is responsible for every delay.
For example, an eight-second response could be delayed by document retrieval, external API calls, model inference, or output validation. The first step is to measure each stage and optimize the actual bottleneck.
Trace requests through authentication, routing, retrieval or tool calls, context assembly, inference, validation, and response delivery.
- Interactive workloads: Measure time to first token (TTFT), total response latency, and p95/p99 latency rather than relying only on averages.
- Batch workloads: Monitor job completion time, processing throughput, backlog age, and cost per successful output.
Optimization strategies¶
Different bottlenecks require different approaches:
- Retrieval-bound: Optimize search queries, indexing, candidate count, and reranking. Parallelize independent retrieval operations where appropriate.
- Inference-bound: Reduce unnecessary context, evaluate faster models, optimize output length, use prompt caching, or select suitable inference capacity.
- Integration-bound: Set appropriate API timeouts, limit excessive tool calls, and execute independent operations concurrently where safe.
- Batch-bound: Use asynchronous processing, dedicated workers, controlled concurrency, and checkpointing for long-running jobs.
Performance improvements must not compromise answer quality. For example, retrieving fewer documents may reduce latency but also exclude evidence needed for an accurate response. Validate optimizations against the application's quality and latency requirements before adopting them.
Streaming and response delivery¶
Streaming can improve perceived responsiveness by delivering model output incrementally instead of waiting for the complete response.
However, the delivery strategy must account for validation and security:
- Stream incrementally when partial content can be safely displayed.
- Buffer and validate when sensitive information, structured output, or evidence checks must pass before disclosure.
- Propagate cancellation to downstream inference operations where supported to reduce unnecessary processing.
For example, Amazon Bedrock Guardrails supports synchronous streaming checks that buffer content before release and asynchronous checks that prioritize responsiveness but can expose content before a violation is detected.
Once sensitive information has reached the client, retracting it from the UI does not undo the disclosure.
Choose the response-delivery strategy based on latency requirements and the consequences of releasing unvalidated content.
See Amazon Bedrock — Streaming Guardrails.
Scaling, concurrency, and isolation¶
Different workloads may share the same GenAI platform, but they don't have the same resource requirements or business priorities.
For example, a large backlog of weekly reporting jobs should not delay an on-call engineer investigating a production incident.
The architectural goal is to scale each component according to its bottleneck while preventing one workload from exhausting resources needed by others.
Scaling considerations¶
Different parts of an LLM application scale independently:
- API and orchestration: Stateless application instances can scale horizontally based on request volume and resource utilization.
- Model inference: Capacity depends on the serving configuration, provider quotas, and available model throughput. Adding API replicas does not increase inference capacity.
- Retrieval and data services: Search indexes, databases, and external APIs have their own throughput and connection limits.
- Asynchronous processing: Batch workers can scale independently based on queue depth, processing capacity, and job deadlines.
Workload isolation and overload management¶
For our Enterprise IT Operations Assistant:
- Prioritize critical workloads: Protect sufficient capacity for incident investigation during periods of heavy demand.
- Isolate batch processing: Use separate worker pools, concurrency limits, or inference capacity allocations where appropriate.
- Enforce resource limits: Set concurrency, token-consumption, request-rate, and queue-wait budgets for each workload.
- Handle overload explicitly: Apply backpressure, reject excess requests, or defer lower-priority jobs rather than allowing queues to grow indefinitely.
- Control retries: Use bounded retries with backoff and jitter. Respect request deadlines and make retried operations idempotent where necessary.
Prioritization should not mean that lower-priority workloads wait indefinitely. Define acceptable waiting times and reject or defer work when those limits cannot be met.
Model fallback also requires planning. If the preferred model is unavailable, route requests only to alternatives already evaluated and approved for that workload. An available model is not necessarily a suitable replacement.
The objective is to maintain predictable service behavior during peak demand and partial failures—not simply to process the maximum possible number of requests.
Caching strategies¶
Production LLM applications often repeat expensive operations: processing common instructions, generating embeddings, retrieving similar documents, or answering recurring questions.
Caching can reduce latency and cost by reusing this work. However, unlike traditional static-content caching, LLM applications frequently operate on user-specific, time-sensitive, and access-controlled information.
The architectural decision is what to cache, where to cache it, and when cached information is no longer safe to reuse.
Caching options¶
| Cache level | What is reused | Key consideration |
|---|---|---|
| Embedding | Vector representations for unchanged inputs | Embedding model/version compatibility and content changes |
| Retrieval | Search results or document references | Freshness, authorization, tenant isolation |
| Prompt | Repeated model-input prefixes, such as system instructions and shared context | Model/API support, cache eligibility, sensitivity, and economics |
| Response | Previously generated answers to equivalent requests | Stale evidence, permissions, and answer correctness |
Each approach optimizes a different operation. Not every application needs all four.
Applying caching to our operations assistant¶
- Employee Q&A: Frequently requested, stable runbook information may benefit from retrieval or response caching, subject to authorization and document freshness.
- Incident investigation: Stable prompt instructions may be reusable, but live metrics, deployment states, and incident evidence generally require fresh retrieval.
- Operations reporting: Repeated embeddings or retrieval of unchanged, versioned documents can reduce processing costs across scheduled jobs.
For example, a cached explanation of the incident escalation procedure may be valid for a defined period. A cached answer describing the current health of a production API could become misleading within seconds.
Cache correctness and security¶
For every cache, establish:
- Scope: Global, tenant-specific, user-specific, or session-specific.
- Validity: Content versions, model configurations, and policy dependencies.
- Expiration and invalidation: TTLs, document updates, access revocations, and operational changes.
- Authorization: Verify that cached information remains accessible to the requesting identity.
- Effectiveness: Measure hit rate, latency reduction, and net cost savings.
A cache must not bypass current authorization or serve information invalidated by policy changes.
AWS implementation: Bedrock prompt caching¶
Amazon Bedrock supports prompt caching for compatible models and inference APIs.
- Implicit caching: Attempts to reuse eligible repeated prompt prefixes automatically.
- Explicit caching: Uses supported cache checkpoints or controls to identify reusable prompt content.
Stable system instructions and shared reference material are potential candidates. Availability, minimum token requirements, retention, and pricing depend on the model and API.
A repeated prefix does not guarantee a cache hit. Measure cache-read/write tokens and actual savings before adopting prompt caching broadly.
See Amazon Bedrock — Prompt Caching.
Cost management¶
Model pricing is only one component of the total cost of running an LLM application.
Consider:
- Inference: Input/output tokens, model selection, and serving capacity.
- Data processing: Embeddings, reranking, retrieval, and storage.
- Application infrastructure: Compute, orchestration, queues, and networking.
- Operational overhead: Retries, evaluation, monitoring, and observability.
- Optimization economics: Cache writes, reads, storage, and invalidation overhead.
Measure cost per successful task, not simply cost per token or model invocation.
For example, a cheaper model may require repeated calls, additional validation, or escalation to a stronger model. If it frequently fails quality requirements, its effective cost per successful incident analysis may exceed that of a more capable model.
Track cost by workload, model, and application where practical, alongside quality and latency metrics.
The objective is the lowest sustainable cost that meets the workload's quality, security, and performance requirements—not the lowest model price.
Resilience, degraded modes, and observability¶
Production LLM applications depend on multiple services: model inference, retrieval, enterprise APIs, and identity systems. Any of these dependencies can fail, become slow, or temporarily exceed capacity.
Resilience is about designing how the application behaves during these failures—not just how quickly it recovers.
Failure handling and degraded modes¶
Not every dependency failure needs to result in a complete application outage. Depending on the workload, the system may continue operating with reduced capabilities.
Consider these design options:
- Partial results: Return verified information from available sources while clearly identifying missing evidence.
- Retrieval-only mode: Provide authorized document links when generation is unavailable but search remains operational.
- Approved model fallback: Use an alternative model only when it meets the workload's quality and security requirements.
- Fail-closed authorization: Withhold protected information when permissions cannot be verified.
Applying this to our Enterprise IT Operations Assistant:
Suppose the incident copilot cannot retrieve telemetry during an investigation.
- The telemetry adapter returns a timeout or dependency error.
- The application records that telemetry evidence is unavailable.
- Other authorized sources, such as deployment history and incident records, may still be used.
- The response clearly indicates that the investigation is incomplete.
This allows engineers to continue their investigation without presenting missing evidence as a confirmed finding.
Observability: measure more than application health¶
Traditional application metrics remain essential, but LLM systems also need visibility into inference behavior, answer quality, and security controls.
Monitor four areas:
- User experience: Response latency, error rates, timeouts, and cancellations.
- Capacity and cost: Token usage, inference throttling, queue age, concurrency, and cost per successful task.
- Answer quality: Correctness, evidence support, invalid responses, and appropriate abstention.
- Security: Authorization failures, guardrail interventions, access revocations, and tool-execution decisions.
Use request tracing and correlation identifiers to identify which component caused a failure or slowdown.
Logging should preserve enough diagnostic information to investigate problems without unnecessarily retaining sensitive prompts, responses, or operational evidence.
AWS implementation: Amazon Bedrock¶
Amazon Bedrock provides model invocation logging for supported inference APIs, with destinations including Amazon CloudWatch Logs and Amazon S3.
When enabled, invocation logging can capture request and response content, token usage, and associated metadata.
Before enabling it, define:
- What information should be logged.
- Who can access the logs.
- Encryption and retention requirements.
- How sensitive information will be protected.
Model invocation logging is disabled by default and should be configured deliberately based on security and operational requirements.
See Amazon Bedrock — Model Invocation Logging.
Recovery and backlog management¶
Recovery also requires controlled behavior.
For example, after an inference service recovers, hundreds of queued reporting jobs may become eligible for processing simultaneously.
Rather than restarting everything at once:
- Resume queued work at a controlled rate.
- Respect inference quotas and concurrency limits.
- Preserve sufficient capacity for interactive requests.
- Avoid uncontrolled retries that overload a recovering dependency.
The objective is predictable operation during failure and controlled recovery afterward, without compromising security or overwhelming shared services.
7. Architecture Decisions and Review¶
Architecture decisions and review triggers¶
A production GenAI architecture is not a one-time design. Models evolve, inference costs change, new capabilities become available, and operational requirements grow.
The important outcome of the design process is a set of well-reasoned decisions, supported by evidence and clear conditions for revisiting them.
What to capture in an architecture decision¶
Keep each Architecture Decision Record (ADR) focused on:
- Context and requirements: The problem, workload, constraints, and non-negotiable requirements.
- Decision and rationale: The selected approach and why it fits.
- Alternatives and trade-offs: What was considered, rejected, or accepted as a limitation.
- Validation: What measurements or tests must confirm the decision.
- Review triggers: Changes in requirements, technology, cost, or evidence that should prompt reconsideration.
Decisions should be driven by workload requirements and measured results. A weighted comparison can help evaluate alternatives, but it should never override mandatory security, correctness, or compliance constraints.
Architecture decisions: Enterprise IT Operations Assistant¶
The following decisions establish the proposed architecture for our reference application. Each records a selected approach, the alternatives considered, and the conditions that could justify reconsideration.
| Decision | Selected approach | Alternatives considered | Rationale and review trigger |
|---|---|---|---|
| ADR-01: Application deployment architecture | Start with a modular application; deploy reporting workers independently. | Fully distributed microservices from the beginning. | Reduces operational complexity while supporting independent batch scaling. Revisit when team ownership, deployment cadence, scaling, or security boundaries require separation. |
| ADR-02: Workload execution pattern | Synchronous request-response for interactive Q&A and incident investigation; asynchronous job processing for scheduled reports. | Execute all workloads synchronously or asynchronously. | Interactive tasks need timely responses; reporting benefits from durable background processing. Revisit when execution times or user interaction requirements change. |
| ADR-03: Model hosting and inference | Use managed foundation-model inference initially, with workload-appropriate serving configurations. | Self-hosted models or hybrid inference infrastructure. | Avoids managing model-serving infrastructure while workload demand is being established. Revisit based on measured cost, latency, capacity, data residency, or control requirements. |
| ADR-04: Model routing strategy | Use deterministic, task-based routing among approved models. | AI-based classification or hybrid routing. | The three workloads are identifiable through application context. Revisit if ambiguous requests become common and evaluation demonstrates benefits from adaptive routing. |
| ADR-05: Enterprise system integration | Access knowledge and operational systems through controlled, read-only service adapters. | Direct model-driven access to backend systems or broad autonomous tool execution. | Provides explicit contracts, authorization enforcement, and failure isolation. Revisit when controlled operational actions become a business requirement. |
| ADR-06: Conversation state management | Keep application processing stateless where practical, with conversation and job state stored externally. | Instance-local sessions or sticky-session affinity. | Supports horizontal scaling, recovery, and consistent request handling. Revisit when latency, retention, or isolation requirements change. |
| ADR-07: Response delivery strategy | Support streaming for suitable interactive responses; buffer outputs requiring complete validation before release. | Always stream responses or always wait for complete generation. | Balances perceived responsiveness with output validation and disclosure risks. Revisit based on measured latency and workload-specific safety requirements. |
| ADR-08: Caching strategy | Apply selective caching to stable, reusable operations; avoid general-purpose caching of live incident answers. | No caching or broad response caching across workloads. | Reduces repeated processing without compromising data freshness and authorization. Revisit when measured latency, cost, hit rates, or invalidation capabilities justify a change. |
These decisions describe the proposed architectural baseline, not a claim that the alternatives have been benchmarked or the implementation has been deployed.
Each decision should be validated during implementation and updated when its assumptions no longer hold.
Architecture review checklist¶
Before approving a production LLM application, verify that the architecture addresses the following:
- Workloads: Are the use cases, quality expectations, latency targets, and processing patterns clearly defined?
- Models and inference: Have models and serving approaches been evaluated against workload-specific requirements, including cost and capacity?
- Prompt and context: Are instructions, evidence selection, context limits, and output contracts explicitly designed and testable?
- Enterprise integration: Are authoritative data sources, tool interfaces, permissions, and dependency failures accounted for?
- Evaluation: Are representative test datasets, acceptance thresholds, and release-validation processes established?
- Security: Are authentication, authorization, data protection, prompt-injection risks, guardrails, and action permissions addressed?
- Production operations: Are scaling, workload isolation, caching, resilience, observability, and cost controls defined?
- Architecture decisions: Are important trade-offs documented, validated, and linked to clear review triggers?
A production LLM architecture is successful when its decisions are purposeful, measurable, secure, and operationally sustainable.
The objective is not to use the most models, tools, or services. It is to build a system that consistently meets its business and engineering requirements—and can evolve as those requirements change.
Related architecture and references¶
- Designing Production-Grade Enterprise RAG — knowledge lifecycle, retrieval, authorization-aware evidence, and freshness.
- Amazon Bedrock model inference — conversational APIs and streaming.
- Amazon Bedrock inference profiles, application inference profiles, and supported destinations — infrastructure routing, usage attribution, and Region/SCP constraints.
- Amazon Bedrock Provisioned Throughput and batch inference — serving-capacity choices.
- Amazon Bedrock prompt caching and structured outputs — supported inference capabilities and limitations.
- Amazon Bedrock Guardrails and model/RAG evaluations — safeguard and evaluation features.
- AWS Well-Architected Generative AI Lens — production design considerations.
