Skip to Content
Self-hostingTGIGuardrails

TGI guardrails

Guardrails on TGI follow the same progressive enforcement model as other inference backends: instrument first, alert second, block last.

Progressive tiers

TierEnforcementTGI-specific implementation
SoftAlerts onlyPager on queue depth and P95 TTFT from Observability
MediumRuntime limitsPer-tenant rate limits at ingress; max_tokens required in API schema
HardCI + server block--max-total-tokens enforced; CI fails on agents missing output caps

Start at soft. Move to medium when you have two weeks of baseline metrics. Move to hard when a single runaway agent can exhaust GPU memory.

Server-side caps

Configure on the TGI server:

--max-input-length 4096 \ --max-total-tokens 8192

TGI rejects requests that exceed these limits regardless of client behavior. This is your last line of defense — not your only control.

Client-side requirements

Every call through the TGI API must include max_tokens:

await client.chat.completions.create({ model: "meta-llama/Llama-3.1-8B-Instruct", messages: messages, max_tokens: 256, // required — never omit });

Add a lint rule in CI that fails when max_tokens is missing from agent tool definitions.

Ingress rate limits

TGI does not ship per-tenant isolation. Enforce at the gateway:

ControlExample
Requests per minute60 RPM per API key
Concurrent connections10 per tenant
Payload sizeReject prompts > 32 KB at ingress

Pair rate limits with span tags (feature, session_id) so alerts name the route, not just the pod.

Anti-patterns

Anti-patternWhy it fails
max-input-length at model maximum for all routesKV cache exhaustion; terrible batching
Soft alerts with no ownerQueue depth spikes for weeks before anyone acts
Client-only caps, no server flagsOne buggy agent bypasses everything
One deployment for unrelated model tiersCannot cap or scale tiers independently

Spike alerts

Page when a feature’s token burn hits 4× week-over-week. Slice by feature and model_id span tags — not by invoice line items you get weeks later.

Last updated on