LESSON 90 / 215·2 min readIntermediate

Validation, rate limiting, and secure database access

Must knowConcept lesson
01 Understand02 Recall03 Prepare

Words made simple

A few useful meanings before you read the explanation.

API
A way for one piece of software to ask another for data or an action. A claims API might return the current status of a claim.
LLM
A model trained to work with language. It can write or summarize text, but its answer still needs checking against reliable information.
Token
A small piece of text processed by a model. It may be a whole word, part of a word, or punctuation.
More words from this lesson
Schema
A description of the fields and value types that data should contain. It helps check that an answer has the expected shape.
Authentication
Checking who a user or service is, such as by verifying a login session.
Authorization
Checking what that identity is allowed to read or do. Being logged in does not grant access to every record.
Tenant
A customer or organization whose data must stay separate from other customers in a shared application.
Redis
A fast data store commonly used for caching, temporary state and job queues. Choose persistence settings to match the data you must retain.

Overview

  • Input validation checks permitted shapes and values; output validation checks generated data before use.
  • Rate limiting constrains requests or resources by user, tenant, and operation.
  • Secure tool services mediate database/API access through known business functions.

Why this matters

A model can generate malformed input, expensive calls, or unsafe queries even when the request appears ordinary.

An everyday example

A bank teller accepts approved transaction forms with limits instead of handing customers unrestricted database access.

A technical example

Allow getClaimStatus(claimId) with ownership checks instead of runQuery(queryText) with production credentials.

How it works

  1. Parse schema
  2. Apply length/range/business constraints
  3. Authorize
  4. Enforce resource quota
  5. Run parameterized service operation
  6. Validate/project result.

Architecture and flow

See below.

The insurance assistant example

Claim tools query only permitted collections/fields and never expose password-reset tokens or arbitrary aggregation pipelines.

When to use it

Every model-to-tool and tool-to-system boundary.

When to avoid it

Avoid LLM → direct database access with broad credentials; prompt instructions cannot prevent destructive or overbroad queries.

Interview answer

“The model proposes a typed business operation. My tool layer applies authorization, validation, limits, and business logic before any database or API call.”

Benefits, trade-offs, and production considerations

  • Syntax validation does not prevent expensive valid queries.
  • Add bounded pagination, query budgets, field projections, network deadlines, and circuit breakers.
  • If text-to-SQL is required, prefer a separately secured read-only analytics environment with enforced query constraints.
Architecture at a glanceFollow the arrows to see how the parts connect.

Preparing the architecture diagram…

Read the full diagram flow
flowchart LR
  L[LLM proposal] --> T[Allowlisted tool]
  T --> A[Authentication and authorization]
  A --> V[Schema and business validation]
  V --> R[Rate and resource limits]
  R --> B[Business logic]
  B --> D[Database or approved API]
  D --> O[Minimal validated result]
  • The tool names the permitted operation.
  • Authorization verifies the caller's rights.
  • Validation checks arguments and current rules.
  • Limits control abuse and runaway costs.
  • Business logic preserves domain invariants.
  • The final projection removes unnecessary data before returning it to the model.

Common production mistakes: securing only the UI, treating citations as proof of safety, forgetting tenant scope in Redis keys, logging full prompts by default, allowing arbitrary source URLs, and assuming a model refusal is equivalent to an enforced permission denial.


PAUSE & RECALL

Can you explain it without the notes?

Validation, rate limiting, and secure database access

Use your own words. Explain an example and one limitation before checking the explanation.

Check your explanation

Input validation checks permitted shapes and values; output validation checks generated data before use. Rate limiting constrains requests or resources by user, tenant, and operation. Secure tool services mediate database/API access through known business…

CONNECT IT TO YOUR INTERVIEW

Turn this concept into a clear answer.

Practice this concept
YOUR NEXT STEP

Keep connecting the ideas.

Next lesson: Input, output, and tool guardrails

Adapted from 13_AI.MD · “Validation, rate limiting, and secure database access”. Examples are study fragments; framework behavior can depend on your version.