An LLM can interpret a request and propose a response or action. It cannot, by generating a confident sentence, prove that your application checked permissions, changed its database, collected payment, or completed a workflow. Your backend must remain the authority that supplies trusted data, enforces rules, validates model output, performs approved operations, and records what happened.
A convincing answer is not a completed operation
Suppose someone asks an assistant to order a pizza. The model can understand the request and produce a sentence such as “Your pizza has been ordered.” That sentence is not evidence that the restaurant had the item, the address was valid, payment succeeded, an order was saved, or the restaurant received it.
As an Amazon Associate I earn from qualifying purchases.
The distinction is between language and application state. The model produces output; your software determines whether that output is permitted, whether it is valid, and what—if anything—should happen next. A user-facing confirmation should describe an outcome the application has actually verified, not one the model merely predicted or asserted.
What belongs to the model and what belongs to the application
Use the model for tasks where language understanding or generation helps: interpreting intent, extracting fields, summarizing, drafting, and selecting among capabilities the application makes available. Keep authority over consequential behavior in ordinary application code.
#1 Best Overall
- Authentication and authorization: identify the user and decide which operations that user may perform.
- Business rules: check conditions such as availability, eligibility, limits, and required workflow steps.
- Validation: verify model-produced fields against the expected schema, allowed values, and application constraints.
- Transactions and persistent data: commit approved changes and preserve the authoritative record of state.
- Payments, APIs, and other side effects: call external systems through controlled application paths and handle their actual results.
- Security: treat user input and model output as untrusted, and do not let generated text bypass permission checks.
A model may request a capability, such as “create an order,” but the backend decides whether to offer that capability in this context and executes it only after its checks pass. The response to the user should be based on the operation’s returned status and persisted result.
Choose an integration pattern around the workflow
There is no requirement to move every model call into a separate service or introduce an agent framework. A guide from Learn Backend, last verified August 23, 2026, describes six patterns for adding LLM work to an existing backend. The useful choice depends on whether a user is waiting, how failures should behave, whether current application data is needed, and whether the model is adding a feature or replacing existing logic.
| Pattern | Use it when | Key design decision |
|---|---|---|
| Inline endpoint | A person needs the result during the current request. | Set a hard timeout within the endpoint’s latency budget and define a degraded response for optional model features. |
| Queue worker | The task can finish after the user’s request, such as enrichment or batch processing. | Make retries, backoff, dead-letter handling, concurrency limits, and idempotent writes explicit. |
| Internal LLM gateway | Multiple features or teams need shared provider-key handling, model routing, caching, or spend attribution. | Centralize only when there is a real shared need; a gateway for a single call site can add needless ceremony. |
| Read-path retrieval | The model needs private or current application data that is not already in its context. | Retrieve relevant data and pass it as context; use existing infrastructure where practical. |
| Event-driven enrichment | An existing domain event can trigger model work without delaying the original workflow. | Validate the enriched value before saving it, and make the write safe to retry. |
| Feature-flagged parallel path | You are evaluating a model against existing deterministic behavior. | Keep serving the established path while comparing results in the background, then inspect disagreements before gradual cutover. |
When the user is waiting, bound the model call
For interactive work, call the model as part of the request only if its latency fits the endpoint’s budget. Set an explicit timeout rather than allowing the request to wait indefinitely. Decide in advance what the application returns when the model times out or is unavailable: for an optional summary, for example, the rest of the page may still load without it. For a required operation, report that it could not be completed rather than implying success.
What’s actually slowing this PC down?
Pick the symptom - the matching free tool is one click away.
Keep the model call outside database transactions. A slow or failed provider request should not hold locks or leave a transaction open while the application waits. Once a response arrives, parse and validate it, then perform the relevant database work under the application’s normal transaction and authorization rules.
When nobody needs to wait, use asynchronous work
Enrichment, bulk processing, and work triggered by a domain event often belong in a queue worker or event consumer. The original request can finish without waiting for model output; the worker handles the task independently and records its result when valid.
- Use bounded retries with backoff so temporary failures do not create an uncontrolled retry storm.
- Define what happens when retries are exhausted, such as routing the job to a dead-letter queue for inspection.
- Set concurrency limits to control downstream load and model usage.
- Make writes idempotent so replaying a job does not create duplicate records or repeat a consequential side effect.
- Track completion and failure in application state rather than treating a queued job as a completed result.
Ground answers in application data without overbuilding retrieval
If the answer depends on private, changing, or otherwise unavailable application data, the model needs relevant data supplied by the application. Retrieval-augmented generation (RAG) is one approach: retrieve relevant records and provide them as context for the model’s response. The answer is still generated output, so the application should preserve the distinction between retrieved facts and verified actions.
If your system already uses PostgreSQL, pgvector is one option for storing and retrieving embeddings. But retrieval infrastructure is not automatically necessary: a small corpus that fits in the prompt may be simpler to provide directly. Choose retrieval when the size, freshness, or relevance of the data calls for it, not merely because the feature uses an LLM.
Do these 3 things before closing this tab:
1Repair Windows errors before they cause bigger problems2Fix the driver behind crashes, sound loss and screen glitches3Clear out junk files and repair common Windows errorsValidate output before it reaches state or users
Model output is untrusted input, even when it appears well-formed. Parse it, check it against an expected schema or enum, and apply application-specific validation before storing it or taking action. Reject or safely handle missing, malformed, or out-of-range values instead of letting them silently become authoritative.
For reliability, the Learn Backend guide also recommends explicit timeouts, a defined degraded path, output-token caps, cost metering, and backoff for rate limits. These are practical controls to tune to your workload; they do not imply that every provider or application has the same latency or failure profile.
Replace deterministic logic only after comparing behavior
If a model is intended to replace an established rule-based path, do not make it authoritative on the strength of a few plausible outputs. Run it in a feature-flagged parallel path: continue serving the incumbent result while the model produces a comparison in the background. Review disagreements, identify which behavior is correct, and cut over gradually only when the comparison supports doing so.
This pattern is especially useful when the existing behavior has clear rules or consequential outcomes. It lets you learn where the model is useful without making its output the source of truth before the application is ready.
Quick Recap
A practical decision checklist
- Does the user need the answer now? If yes, use an inline call with a hard timeout and a planned degraded path; otherwise, consider a queue or event consumer.
- Does the answer require current or private data? Retrieve and supply the necessary application context, choosing the simplest approach that fits the data.
- Could the output change state or trigger an external effect? Authenticate and authorize in the application, validate the output, execute through controlled code, and record the real result.
- Are multiple features sharing operational needs? Consider a gateway for shared routing, keys, caching, or cost attribution; avoid building one just to wrap a single call.
- Is the model replacing existing behavior? Compare it in parallel behind a feature flag before shifting traffic or authority.
- What happens on timeout, rate limit, malformed output, retry, or replay? Specify those paths before relying on the model in production.
Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.




