The Gemini pipeline — prompts, fallbacks, BYOK, and JSON discipline
Every LLM engineering decision in zoth and traverse, at code level — the highest-signal interview material.
Know your own system
Two LLM integrations, both yours. The engineering (not the prompt text) is what interviewers probe — and you have unusually concrete answers.
Zoth's advisory pipeline (internal/services/rag/)
Calls (all optional-gated on GEMINI_API_KEY):
AnalyzeRequest→ risk score + reasoning for the approver (stored on the request row).PredictApproval→ likelihood + ETA (calibrated against historical decision rows retrieved from the corpus).SuggestDuration→ recommended expiry for the requester.SuggestPolicy→ policy JSON authored from an uploaded security document (the most ambitious: document → structured JSONB, validated byParseAccessRulesbefore storage — LLM output must pass the same validation as human input; that sentence is the entire lesson).ShouldAutoApprove→ the gate for the LOW-sensitivity auto-approve track (tenant opt-in + >95% historical approval rate conditions).
Failure discipline: every call has a timeout and a fallback (heuristic defaults: risk = MEDIUM, duration = policy max); LLM failure never blocks a request — the advisory layer is best-effort by construction. The advisory write path: separate SetAdvisory/SetRiskScore repository methods, so the advisory data physically cannot touch status.
Traverse's AI ladder (BYOK + providers)
Order: user-supplied Gemini key (BYOK, stored per user) → server Gemini → Groq (with model selection, groq:top_models cached 35 days) → G4F (free proxy). Details that show production thinking: per-provider 15 s timeout (the original latency culprit — Day 7); the ladder is sequential with fallthrough on error; responses are JSON-cleaned before parsing (LLM JSON arrives wrapped in markdown fences, with trailing commas, or prefixed with prose — the cleaning function strips fences, extracts the outermost {...}/[...], repairs trailing commas — because "the model returns valid JSON" is not a guarantee, it's a hope); parsing failures fall back to deterministic heuristics (the scheduling layer must never depend on AI success — Day 74's theme).
Premium gating as a choke point: aiAnalysis.queue.ts:143 nulls cognitiveTier/recallScore for free users — one code path, not scattered checks. Design principle: gate at the boundary where data enters the system, not at every read.
The patterns to name (this is the interview payload)
- Advisory-vs-authoritative separation: LLM output lands in dedicated columns/statuses; authority lives in deterministic code. Structurally enforced (separate repository methods, policy-gated reachability).
- Validated LLM output: any LLM-authored artifact that becomes data (policy JSON) passes the same validator as human input. Never
JSON.parse → store. - Graceful degradation everywhere: heuristic fallbacks per feature (risk, duration, tier, schedule) — the system's correctness never depends on a provider being up.
- Provider abstraction + BYOK: key resolution is a policy (user key → server key → fallback), and the AI worker is provider-agnostic. That's the shape of every serious LLM integration.
- Cost/latency control: model selection, response caching where safe, timeouts per provider, and — in traverse's case — moving the whole thing off the request path (the 50× story).
- JSON discipline: cleaning, extracting, repairing; schema validation before use; failures counted (not silently defaulted — log the fallback so you can measure the ladder's health).
Bulletproof your resume
Say these answers aloud before moving on
These are the follow-ups an interviewer will actually ask about your projects.
How do you make an LLM integration production-safe?
Six rules from my two implementations: (1) LLM output never holds authority — it writes advisory columns, never status; (2) any LLM-authored artifact that becomes data passes the same validator as human input (my policy suggestions go through ParseAccessRules before storage); (3) every call has a timeout and a heuristic fallback, so provider outages degrade features, never correctness; (4) JSON is cleaned and validated — fences stripped, outer object extracted, parse failures counted; (5) keys resolve as a policy (BYOK → server → fallback) so the integration is provider-agnostic; (6) expensive calls live off the request path (my 50× latency fix was moving the ladder behind a queue).
What's BYOK and why does it matter architecturally?
Bring-your-own-key: users supply their own Gemini key, which we store and prefer over server keys. Architecturally it does three things: shifts inference cost to power users, gives them quota/latency control, and — the design tension — makes the AI worker multi-tenant over credentials, so key resolution becomes a policy layer (user key → server key → Groq → G4F) with per-key failure isolation. It also means key storage is a security surface: I'd want the same encryption envelope zoth uses for integration credentials (AES-256-GCM) — traverse currently stores them more simply, which I'd flag as a hardening item.
Your scheduling depends on AI output. What if the model is wrong?
It can't be catastrophic by design: the AI contributes signals (cognitive tier, recall score, tags) while the scheduler's core inputs are behavioral (solves, attempts, outcomes) — and premium gating deliberately nulls AI signals for free users, so the deterministic path is exercised continuously, not just in outages. Wrong-but-plausible AI output shifts schedule aggressiveness; it can't corrupt history, because attempts and revisions are recorded facts. Plus the calibration harness (Day 72) measures predicted-vs-observed, so systematic model error becomes visible instead of invisible.