DEV Community

Amit chakraborty
Amit chakraborty

Posted on Originally published at amitchakraborty.dev

Deterministic Fallbacks for Every AI Path

In the pursuit of building high-stakes AI systems, the most dangerous architectural decision is to assume the model will work. Whether it is a rate limit, a hallucination, or a latent failure in a retrieval-augmented generation (RAG) pipeline, non-deterministic systems eventually fail in ways that traditional software does not.

Over the last eight years of professional software engineering, I have shipped 18 production applications across mobile, web, and desktop. My experience as the founding engineer at Synapsis Medical Technologies, where I led the architecture of a HealthTech AI platform from 0 to 1, taught me that "99.9% uptime" for an AI service is a hollow metric if the 0.1% failure occurs during a critical clinical workflow. To maintain that uptime across our RAG pipelines, we had to move beyond simple error handling. We had to design systems that remained useful even when the model was effectively switched off.

The Fragility of the "AI-First" Interface

The industry currently favors "AI-first" interfaces: a blank chat box or an agentic loop that handles the entire user intent. This is high-risk. If the LLM fails to parse the intent or the underlying vector database returns low-confidence chunks, the user is left with a "Something went wrong" message.

In health technology, where I integrated wearables, FHIR/HL7 data, and clinical AI, a failure isn't just a bad user experience; it is a data integrity risk. When I scaled our engineering team from 0 to 21 engineers in 13 months, one of our primary architectural pillars was the "deterministic shadow." For every AI-driven feature, there must be a hard-coded, rule-based path that provides at least 60% of the value with 100% predictability.

Architecture of the Deterministic Shadow

When I owned the React Native, Next.js, and NestJS architecture at Synapsis, we treated the LLM as a progressive enhancement rather than a core dependency. This approach requires a three-tier execution strategy:

  1. The Intent Router (Deterministic): Before a prompt hits the model, a regex or keyword-based router checks for high-certainty triggers. If a user asks for "last night's heart rate," we do not need an LLM to figure out the query parameters for the wearables API.
  2. The Augmented Path (Stochastic): This is the RAG pipeline. It retrieves context, synthesizes an answer, and presents it.
  3. The Fallback UI (Deterministic): If the RAG pipeline latency exceeds a threshold or the model output fails a validation check (such as PII detection or medical safety guardrails), the system reverts to a structured dashboard or a standard search interface.

By implementing this, we ensured that the clinical AI remained functional. If the synthesis failed, the clinician still saw the raw, filtered data retrieved from the FHIR server. The system stayed useful because the fallback was not an error message; it was the underlying data presented without the "AI" layer.

Trade-offs in Guardrails vs. Latency

Maintaining high uptime for AI services requires aggressive validation. In our HIPAA-aligned pipelines, we implemented a "double-check" pattern: a smaller, faster model or a set of deterministic rules validates the output of the primary model.

The trade-off here is latency. Every validation step adds milliseconds. When I overhauled our CI/CD across five production systems—cutting release cycles from 2 days to 4 hours—I applied the same philosophy to our runtime: automate the safety checks so they are part of the pipeline, not an afterthought.

We categorized failures into three modes:

  • Provider Failure: The API is down or rate-limited.
  • Logic Failure: The model returned a malformed JSON or failed to follow a schema.
  • Safety Failure: The output triggered a HIPAA or clinical safety violation.

For Provider failures, we used a circuit breaker pattern that immediately rerouted traffic to a local, deterministic search algorithm. For Logic and Safety failures, we used "Graceful Degradation." If the AI couldn't summarize a patient's history safely, the UI would simply render the last five clinical notes in a standard list format.

A Worked Example: Wearables Integration

Consider a feature that summarizes sleep data from a wearable device.

The Stochastic Path:
The LLM receives a JSON of sleep stages and heart rate variability (HRV). It generates a natural language summary: "You had a restless night with an elevated heart rate, possibly due to late-night activity."

The Deterministic Fallback:
If the LLM call fails, the NestJS backend identifies the failure and triggers the fallback. The React Native frontend receives a fallback_type: "STATISTICAL_SUMMARY" flag. Instead of a paragraph, the UI renders a pre-defined template: "Sleep Duration: 6h 12m. Avg HRV: 45ms. (Manual Review Required)."

The user still gets their data. The "AI" was an assistant, not a gatekeeper. By building the NestJS services to return structured data alongside the AI's natural language summary, we ensured the frontend always had the raw materials to build a fallback view.

The Cost of Learning Determinism

Building this way is more expensive upfront. It requires you to build the feature twice: once as a standard, data-driven module and once as an AI-enhanced experience.

During the 0 to 1 phase at Synapsis, we initially struggled with the complexity of maintaining two paths for every feature. However, the investment paid off during a major model provider outage. While other platforms went dark, our clinical AI platform remained operational. The "AI" features were temporarily disabled, but the core utility—viewing patient data, tracking integrations, and managing FHIR records—remained 100% functional. This is how we maintained 99.9% uptime.

We also learned that deterministic fallbacks are the best way to debug "vibes." When a model's output feels "off," having a deterministic reference point allows you to run side-by-side evaluations. You can compare the AI's synthesis against the hard-coded statistical summary to detect drift.

Practical Recommendations for Architects

Based on building and scaling these systems, I recommend the following constraints for any production AI implementation:

1. Schema Enforcement is Non-Negotiable

Never accept raw strings from an LLM into your core logic. Use libraries like Zod or TypeBox to validate every response against a schema. If the validation fails, trigger the deterministic fallback immediately. Do not retry more than once; the latency cost is too high.

2. Decouple Retrieval from Synthesis

In RAG pipelines, keep the retrieval logic (the part that queries the vector store or FHIR API) separate from the synthesis logic (the LLM). If the LLM is down, you can still present the retrieved "chunks" or documents to the user. Raw information is better than no information.

3. Implement Semantic Cache with a "Static" Escape Hatch

Use a semantic cache to store common queries. If a new query is similar to a cached one, serve the cached result. If the cache is cold and the model is slow, have a "static" response ready for common intents.

4. Monitor "Fallback Rate" as a Core Metric

We tracked how often our systems reverted to deterministic paths. A rising fallback rate was often an early indicator of prompt drift or upstream data changes in our wearables integrations. It became a more important health signal than simple 200 OK responses.

Conclusion

The goal of a Senior Systems Architect is not to build the smartest system, but the most resilient one. In my transition from founding a HealthTech platform to independent practice, the most consistent lesson has been that AI should be treated as a high-variance worker. You give them a desk and a task, but you never give them the only key to the building.

By building deterministic fallbacks into every AI path, you ensure that your application’s value is not a function of a third-party API’s temperature setting. You build software that works because the logic is sound, and you use AI to make that sound logic feel like magic—until the magic fails, and the logic takes over.


Amit Chakraborty is a founding engineer and senior architect — React Native, AI/RAG systems and production architecture. Portfolio: www.amitchakraborty.dev · LinkedIn · GitHub. Open to senior and founding engineering roles, remote worldwide.

Top comments (0)