Gains:
- Can design the end-to-end architecture that takes an LLM feature from idea to production
- Establishes layers of verification enforcement, human approval, and tracking (logging/metrics)
- Boundaries translate ethics and privacy principles into production decisions
In the previous ten units, we learned the parts one by one: request structure, token economics, flow, system prompt, model selection, cache, batch, error management, secure key and automation. In this last unit, we combine the parts and establish the holistic architecture that carries an LLM feature from idea to production. Production is different from a “working demo”: verification is mandatory, output must be monitored, boundaries and ethical principles must be embedded in decisions. This unit is the carrier column of the module; All the previous ones come together here.
Layers of Production Architecture
A solid LLM qualification consists of roughly five layers:
- Input layer: Collect data, clean it, mask sensitive areas, transmit only what is necessary.
- Model layer: Select the correct model (unit 5), set system prompt and parameters (unit 4), cache (unit 6).
- Validation layer: Check output against schema/rule, source, and human approval if necessary.
- Action layer: Perform action with validated output; Capture high impact actions.
- Monitoring layer: Record and measure every call, cost, error and quality.
These layers are a pipeline; each one checks the output of the previous one.
Why is Verification Required?
LLMs can produce fluent but sometimes inaccurate output. This is called hallucination: the model may fabricate information that appears to be true but is not. In a chat game this is tolerable; cannot be tolerated in a production system (invoice, health, legal, finance). So it turned out, blindly unreliable; is confirmed.
Verification layers (increasing by impact):
- Format/schema validation: Does the output conform to the expected JSON schema? (The structured output largely guarantees this.)
- Rule/logic verification: Are the values reasonable? (Is the amount negative, is the date in the future, is the category valid?)
- Source verification: Is the claim based on the documentation provided? Does the model say something that isn't in the document?
- Human approval: An expert reviews high-impact or ambiguous decisions.
Caution: "The model is so good, no further verification is needed" is the most dangerous production fallacy. No matter how good the model, the verification layer is a safety net in high-impact decisions. Even one wrong automatic decision can take away all the time saved.
Human-in-the-Loop
Not every decision has to be fully automatic. In the human-in-the-loop approach, the model speeds up the work and the human approves it. The right balance depends on the impact of the decision and the reliability of the model on that task.
Impact of the decision
Approach
Low (label suggestion, draft)
Full automation; error is cheap and reversible
Medium (routing, prioritization)
Automation + sampling control
High (money, contract, health, deletion)
Human consent is mandatory; the model only suggests
Monitoring: You Can't Manage What You Don't See
In production, you must monitor every call. Without monitoring, you cannot improve cost, quality, or catch a problem early. Key metrics to record:
- Usage/cost: Per request and total tokens, model distribution, daily spend.
- Latency: Average and worst-case response time.
- Error rate: 429/500 rates, retries, abandonments.
- Quality: Rejected output rate at verification layer, correction rate at human approval, user feedback.
Tip: Do not write sensitive data (personal information, keys) to monitoring logs. Consider logs within the scope of confidentiality; record by masking if necessary (unit 9).
Ethics and Boundaries
Ethical responsibility is as much a part of the production decision as technical accuracy:
- Transparency: The user should know whether they are talking to an artificial intelligence or a human.
- Fairness and bias: The model may carry bias from the data on which it is trained; Monitor discriminatory consequences in high-impact decisions (hiring, credit).
- Liability: If an automated decision causes harm, you are responsible; “The model said so” is not a defense.
- Acceptance of limits: The model cannot perform some tasks reliably; not automating them is also a design decision.
Copiable Templates
# Validation checklist (after output generation)1) Is the schema valid? (structured output validation)2) Do the values make sense? (rule check: range, date, enum)3) Is the claim based on the source? (reject if not in the document)4) Is the impact high? → send for human approval5) If all passed → allow action, save
# System prompt that forces relying on sourceRely only on information in the provided document. Do not add anything that is not in the document. If an information is not in the document, write "Not found in the document". Never guess or make up things.
# Human approval threshold (decision rule)IF decision_type in [money, contract, delete, health] → human approval mandatoryIF model_trust < threshold OR validation "uncertain" → submit to human approvalOTHER → auto apply + sampling control
# Trace log template (writing sensitive data){ "time":"...", "model":"...", "input_token":..., "output_token":..., "delay_ms":..., "stop_reason":"...", "authentication":"passed|rejected|human", "cost_usd":... } // personal data and key are NEVER written
Weak prompt / Strong prompt (production reliability)
# WEAK (no verification, no source, applies automatically) Evaluate this request, make a refund decision and apply.
# STRONG (source-based, generates recommendation, leaves to human approval)Evaluate this return request based on the return policy document only. Recommend decision with justification but do not implement: {"recommendation":"approve|reject","reason":"...","policy_clause":"..."}.If there is no clear basis in the policy document, give "unclear". A representative will approve the final decision.
Powerful version; It attributes the decision to the source, positions the model as a “suggestor” rather than a “doer,” and puts the high-impact step behind human approval. This is the essence of production reliability.
Three Mini Cases
Case 1 — The day the verification layer saved. A fintech was having the model classify transaction descriptions and create automatic accounting records. They added rule validation: once the model output the amount incorrectly (12,500 instead of 1,250 in the document), the "amount does not match the document" rule rejected the output and the record fell to the human. If there was no verification, the incorrect record would silently enter the system.
Case 2 — Fugitive caught by surveillance. A SaaS team had set up a monitoring panel; One morning the daily cost tripled. It was seen from the logs that a client entered a loop and sent the same request thousands of times. They added quota and deduplication; The problem was resolved within hours. Without tracking, the bill would be a surprise at the end of the month.
Case 3 — Accepting the limit. A healthcare startup was planning to make a diagnosis recommendation fully automatically and show it to the patient. In an ethics and liability review, they decided this was off-limits: the model only provides a summary and possible points to a physician, the physician makes the diagnosis. Not automating a job is also a mature design decision.
Common mistakes
- Skipping validation: Blindly applying the output, saying "the model is good".
- Automating high-impact decision: Human approval is essential in money/health/law.
- Not monitoring: Cost and quality problems are discovered late.
- Writing sensitive data to logs: Privacy violation; Save it by masking it.
- Not trying to rely on the source: The model may make up what is not in the document.
- Ignoring limits: Not automating some tasks is the right decision; Transparency and responsibility are yours.
Deeper: Release Management, Rollback, and Incremental Deployment
Taking an LLM feature into production isn't about setting it up and forgetting about it; is to safely modify a live system over time. It has three pillars.
Versioning. Your system prompt, model selection, and verification rules change over time. Version each significant change and record which version is live. If one day the quality drops, "what did we change?" You should be able to answer the question within minutes. In a versionless system, finding the root cause of a regression takes days.
Rollback. If a new prompt or model behaves worse than expected in live, you should be able to quickly revert to the previous, well-known version. A change without a rollback plan is blindly accepting a live risk. "I changed something, it got bad, I can't go back" is the most expensive production scenario.
Gradual rollout. Instead of applying a change to all traffic at once, you roll it out to a small percentage (e.g. 5%) first and monitor metrics (quality, cost, errors). If it's good, you increase the percentage; If it's bad, you'll get it back with only a small section affected. This greatly limits the risk.
These three practices combine techniques from all previous units: eval (unit 5) measures change in advance, monitoring (this unit) gives early warning during propagation, the verification layer catches erroneous outputs before they become actionable. Production is not a single correct setup; It is a continuous discipline that measures, monitors and can change with confidence. The entire module is for you to establish this discipline.
In summary
Production is more than a working demo: it is a pipeline of input, model, verification, action and monitoring layers. The output is unreliable without verification; high-impact decisions are tied to human approval; Every call is monitored for cost, errors and quality. Ethics, transparency, bias control, accountability and acceptance of limits are integral to technical decisions. Every piece learned in this module comes together in this holistic design.
Application task
Design an LLM feature end-to-end. (1) Fill in the five layers (input, model, verification, action, monitoring) for your specific task. (2) Mark by impact which decisions will require human approval. (3) Write at least three validation checks (schema, rule, source). (4) Determine the key metrics you will track and what you will not log. (5) Write a limit and an ethical principle that you accept in this feature.
checklist
- [ ] I can design five layers of the production pipeline.
- [ ] I can validate the output against schema, rule and source.
- [ ] I can set a human approval threshold based on the impact of the decision.
- [ ] I monitor cost, error and quality and practice not writing sensitive data in logs.
- [ ] I can transform ethics, responsibility and boundaries into production decisions.
Module Exam
1. What does the 'system' role do in an LLM chat API?
- A) Gives the model permanent instructions and rules of behavior that apply throughout the entire conversation ✔
- B) Keeps the last question written by the user
- C) Stores the response produced by the model
- D) Encrypts the API key
Description: The system role gives the model persistent instructions, personality, and rules that apply throughout the entire conversation; It is a high-level redirect, separate from user messages.
2. Why is the conversation history (previous messages) sent again each time in an API request?
- A) It is necessary to backup as the server deletes the history
- B) API calls are stateless; ✔ Context is resent on every request because the model doesn't remember history
- C) Required only for invoicing, has no effect on the model
- D) Sending history is mandatory to avoid slowing down the response
Explanation: LLM API calls are stateless; The model does not remember previous rounds, so all relevant history is resent on every request to preserve context.
3. What is a 'token' in LLM pricing?
- A) One-time password used to log in to the API
- B) A fixed fee paid on each request
- C) The smallest unit in which the model processes the text; usually corresponds to word part ✔
- D) A unit that measures only the length of the output
Description: Token is the smallest unit in which the model processes text; It usually corresponds to a fragment of a word, and both input and output are charged based on the number of tokens.
4. Why are output tokens more expensive than input tokens at most LLM providers?
- A) Output tokens are always longer than input
- B) Input tokens are free
- C) Output tokens are sent twice over the internet
- D) Unit cost is higher because output generation requires additional calculations for each token ✔
Description: Each of the output tokens requires the model to perform step-by-step generation (computation); This production cost is higher than processing the input all at once, so the output unit price is usually higher.
5. In what situation is using streaming most beneficial?
- A) In long answers; Reduces perceived delay and prevents timeout ✔
- B) Only in very short, one-word answers
- C) To reduce the cost to zero
- D) To hide the API key
Description: In long responses, streaming reduces perceived latency by making the first words appear immediately and prevents HTTP timeouts at large max_tokens values.
6. What does increasing the 'effort' parameter in modern models generally affect?
- A) Always shorten the answer
- B) Automatically rotates the API key
- C) It only reduces the input token price
- D) Increases thinking depth and token spending; It may improve quality, but it also increases latency and cost ✔
Description: The effort parameter adjusts how deeply the model will think about a task and how many tokens it will spend; Upgrading may improve quality, but it also increases latency and cost. For simple tasks, low effort is sufficient.
7. What is generally the most cost-effective approach to a simple, high-volume classification task?
- A) Always use the most expensive and most powerful model
- B) Calling all models at the same time for each request
- C) Selecting the lightest/cheapest model that accomplishes the task by verifying it with a little eval ✔
- D) keeping the max_tokens value unnecessarily too high
Explanation: If the task is not complex, choosing a faster and cheaper model that easily accomplishes the task (e.g. Haiku class) instead of using the most expensive and powerful model will significantly reduce the cost.
8. In which scenario does prompt caching reduce the cost the most?
- A) When a large and fixed context is used repeatedly across many requests ✔
- B) When a completely different text is sent with each request
- C) When only a single request is made
- D) To reduce output tokens
Description: Caching is a prefix match; In cases where a large, immutable context (system prompt, documents) is reused across many requests, reading from the cache is a small fraction (~0.1x) of the full price.
9. How should I edit the prompt so that the prompt cache hits?
- A) Putting variable content at the beginning and fixed content at the end
- B) Embed the current date and time in the system prompt for each request
- C) Putting fixed content (system prompt, documents) at the beginning and variable content at the end ✔
- D) Changing the order of the tool list with each request
Explanation: Since the cache is a prefix match, fixed/unchanging content (system prompt, documents) is initialized; variable content (date, user question, request ID) is put at the end. Even a single byte changed at the beginning will invalidate the cache.
10. For what type of workload is batch processing best suited?
- A) Live chat where the user expects an instant response on the screen
- B) Just one short question
- C) Generating API key
- D) Jobs that are delay tolerant, large volume and do not require immediate results ✔
Description: Batch processing is suitable for large volumes of jobs that do not require an immediate response and are tolerant of delay; results are delivered after some time, but the unit cost is usually lower.
11. What is used to confidently match which request the results belong to in a batch?
- A) Sending order (position) of requests
- B) Length of answers
- C) Last 4 digits of the API key
- D) A unique custom_id given to each request ✔
Remark: Bulk results may be returned in a different order than the submission order; so it's necessary to match results by ID, not location, with a unique custom_id given to each request.
12. What is the recommended behavior when you receive a 429 (rate limit) error from the API?
- A) Forcing by sending many more requests at the same time
- B) Trying again with exponential backoff, following the retry-after heading ✔
- C) Cancel the request completely and show the error as a crash to the user
- D) Changing the API key
Explanation: 429 is a retryable error; The correct approach is to try again with exponential backoff, respecting the retry-after header. Most official SDKs do this automatically.
13. Which of the following HTTP error codes are generally considered retryable?
- A) 400 (invalid request)
- B) 401 (authentication error)
- C) 529 (server overloaded) ✔
- D) 404 (not found)
Explanation: 429 (speed limit), 500 (server error) and 529 (overload) are temporary errors and can be retried by backing off. Errors like 400 and 401 are request/identity issues; Trying again won't solve it.
14. Which of the following is the secure way to manage API keys?
- A) Storing in the environment variable/hidden manager, not embedding it in the code and rotating regularly ✔
- B) Write the key directly into the source code and send it to the repository
- C) Putting the key in client side (browser) JavaScript
- D) Sharing a single key with the entire team via email
Description: Keys are never written to the source code or repository; It is stored in an environment variable or hidden management tool, granted with minimal privileges, and rotated regularly.
15. What is the best approach to LLM integration with an automation tool (n8n, Zapier, Make) in terms of privacy?
- A) Sending all raw data to the model, even if it is not necessary
- B) Writing the API key in plain text inside the flow step
- C) Minimizing and masking sensitive data and storing the key as secret credentials ✔
- D) Keeping personal data permanently in the flow history
Description: As data entering automation passes through third-party systems and model, sensitive/personal data needs to be minimized, masked and only required fields sent; The API key is also stored as secret credentials within the tool.
16. Why is validation of output mandatory in an LLM based production feature?
- A) Only formatting is required because the model never makes mistakes
- B) Because the model can produce fluidly but sometimes incorrectly; Schema/rule must be audited with resource and human approval ✔
- C) Validation should be avoided because it only increases cost
- D) Verification is only to reduce the number of tokens
Description: LLMs can produce fluent but sometimes inaccurate (hallucinatory) output; so it came out in high impact decisions; It should be audited by schema/rules checking, source validation, and human approval when necessary.