A Guide to LLM Application Development and Operations for Production
This guide abstracts essential capabilities—including prompt orchestration, knowledge supply, tool integration, access control, evaluation, and observability—into a universal methodology for developing and operating large language model (LLM) applications in production. It covers layered architecture, the transition from prototype to release, RAG implementation, tool calling, quality evaluation, security, cost management, and organizational practices to help teams build robust and maintainable generative AI systems.
For a generative AI application to stably serve business needs, it must go beyond simply “calling a model and returning text.” What truly determines production readiness is whether prompt orchestration, knowledge supply, tool calling, access control, evaluation, and observability form a closed loop. This article abstracts these capabilities into a universal LLM application development and operations methodology, enabling teams to adapt it to their own business contexts rather than being tied to a specific product form.
Defining the Problem to Solve
Typical requirements often include three types of goals simultaneously. First, shortening the time from idea to a usable prototype, allowing business personnel to configure prompts, knowledge, and simple workflows. Second, enabling developers to place model calls, data access, and permission checks within controllable service boundaries. Third, quantifying performance, identifying failures, and safely rolling back after launch. Focusing on only one of these often leads to a great demo but an unusable production system, or a complete process with extremely slow iteration.
Therefore, a platform or self-built system should cover two types of capabilities: one akin to Backend-as-a-Service, responsible for users, applications, data sources, keys, and runtime environments; the other akin to LLMOps, responsible for versioning, evaluation, logging, cost management, and exception handling. Both must share the same application definition to avoid scenarios where “configuration is in one place, execution in another, and troubleshooting is nowhere to be found.”
Layered Architecture
It is recommended to divide the system into five layers, communicating only through explicit contracts.
The Access Layer is responsible for identity, quotas, auditing, and request shaping. Externally, it can be a conversational interface, batch processing task, or service call embedded in business systems; internally, it unifies into a standard request: user identity, application ID, session context, input attachments, and trace ID.
The Orchestration Layer is responsible for expanding a single request into multiple steps. Steps can include retrieval, query rewriting, model invocation, calling business tools, summarizing conclusions, or requesting human confirmation. Orchestration results should be serializable for replay.
The Model Layer only exposes a unified inference interface: model ID, message list, sampling parameters, timeout, and maximum output length. Specific models can be replaced, but applications should not directly depend on vendor-specific proprietary fields. If using model inference, object storage, message queues, and container platforms from Baidu AI Cloud or other cloud providers, they should also be integrated through adapters in this layer to prevent business code from being scattered with cloud vendor details.
The Knowledge and Tool Layer provides retrieval, structured data, and external actions. The knowledge base stores document chunks, vector or keyword indices, permission tags, and update timestamps; tools are controlled functions, such as querying orders or creating tickets, rather than arbitrary code execution.
The Observation Layer records input summaries, retrieval hits, model versions, tool input/output, latency, token usage, evaluation results, and user feedback. Sensitive fields are masked by default.
From Prototype to a Releasable Version
A repeatable process usually involves: defining the task and failure criteria, preparing a small set of golden samples, writing system prompts and output constraints, connecting minimal knowledge or tools, running end-to-end, and then performing regression testing. Prompts should not pile up slogans; they should clearly define role boundaries, permitted information, refusal methods when uncertain, and output structures.
An illustrative application definition can remain neutral and versionable:
app: support-assistantmodel: general-chatinput: user_questionsteps:- retrieve:source: help-docstop_k: 5filter: audience=customer- generate:prompt: answer-from-contextrequire_citation: true- guard:block_on: missing_contextpublish:channel: internal-apieval_set: support-v3
The fields above only express intent and are not fixed interfaces of a specific platform. The key point is: retrieval filters, citation requirements, and evaluation sets should be published alongside the application to prevent unreproducible online behavior.
Output constraints should prioritize data formats already used by the team. If the downstream requires database insertion, the model should be required to return fixed fields, and schema validation should be performed on the server side; if validation fails, retry once or downgrade to manual processing. Never write unvalidated text directly into core systems.
Knowledge Enhancement and Tool Calling
Knowledge enhancement is suitable for scenarios where facts change and answers must be traceable, such as policies, product manuals, and internal processes. Before entering the knowledge base, documents should be cleaned of headers and footers, encoding unified, and chunked by semantic boundaries rather than mechanically splitting by fixed character counts. Each chunk should retain its source, effective time, and visibility scope. During retrieval, filter by permissions first, then perform similarity or keyword recall, and finally pass the hit chunks along with the question to the model. When there is insufficient evidence, it should explicitly state that it cannot answer, rather than using general knowledge to fill in the gap.
Tool calling is suitable for scenarios that must read from or write to business systems. Each tool should do only one thing, with parameters described by a structured schema and authorized on the server side. The model can only suggest a call; actual execution is handled by the orchestration layer. High-risk actions, such as refunds, deletions, and external communications, should require human confirmation or secondary validation. Treating “the model says it’s okay” as authorization is a common source of incidents.
Multi-step workflows should limit the number of steps, total latency, and repeated calls. When a step fails, record the failure type and follow a clear branch: retry with backoff for retriable errors, directly reject for permission errors, and ask the user for more information if evidence is insufficient. Infinite loops and implicit retries will amplify costs and latency.
Quality, Security, and Evaluation
Before launch, prepare at least three types of samples: normal questions, boundary questions, and questions that must be refused. Boundaries include expired documents, ambiguous queries, insufficient permissions, and tool timeouts. Evaluation should not just look at “whether it sounds human,” but whether the task is completed, citations match, unauthorized content is leaked, and tool parameters are valid.
Automated checks and manual sampling can be combined. Automated checks are suitable for formats, citation existence, banned words, and pass rates on regression sets; manual sampling is suitable for tone, business judgment, and disputed samples. Every time you modify prompts, chunking strategies, retrieval parameters, or model versions, you should rerun the same evaluation set and retain a diff report. Optimization without a baseline cannot determine whether it is progress or a coincidence.
In terms of security, defend both inputs and outputs. On the input side, identify unauthorized extraction, prompt injection, and oversized attachments; on the output side, filter sensitive information, unauthorized data, and unexecutable promises. System prompts must be separated from user content, and retrieved documents should also be treated as untrusted data, preventing instructions within them from overriding application policies. Keys, connection strings, and internal host information must not enter prompts or logs in plaintext.
Operations, Cost, and Rollback
Production traffic must have rate limiting, timeouts, circuit breaking, and graceful degradation. Degradation can involve switching to a smaller model, turning off non-critical tools, or returning only retrieval summaries. Session state should be externalized for horizontal scaling; long conversations require summarization or window clipping to prevent infinite context growth.
Costs should be attributed by application, department, and model version. Pay attention to the number of retrieval calls, tool calls, input/output length, and failed retries per request. Repeatedly pasting long documents in prompts, setting retrieval top_k too high, and uncached repetitive Q&A can all quietly drive up costs. Short-term caching can be applied to stable knowledge, but the cache key must include permissions and knowledge versions to prevent data cross-contamination.
Releases should use a canary strategy: internal users first, then a small percentage of traffic, and finally full rollout. Each version should retain configurations, prompts, index versions, and model IDs. When hallucination rates, complaints, or latency worsen, roll back by version rather than hastily modifying prompts in production. Incident post-mortems should be able to reconstruct the entire chain using the trace ID.
Organizational Implementation Recommendations
The value of a platform lies not in the length of its feature list, but in whether responsibilities are clear. The business team is responsible for task definition and acceptance samples; developers are responsible for orchestration, tools, and permissions; data teams are responsible for knowledge quality; and operations or platform teams are responsible for quotas, observability, and releases. Applications without samples and clear owners should not enter production.
When starting out, choose a narrow scenario: problems are enumerable, knowledge sources are clear, and failures are tolerable or can be transferred to humans. First, build solid retrieval, citation, evaluation, and logging, then expand workflows and write operations. For every new tool or data source added, complete the permissions, testing, and rollback procedures. A system built this way can evolve as models are replaced, with core assets remaining in prompt versions, knowledge governance, evaluation sets, and operational data—rather than in a single demo.
