Beyond the hallucination: Why AI needs deterministic math

AI excels at discovery and pattern recognition, but financial math demands 100% verifiable, deterministic calculation.

Why core operational metrics demand more than probabilistic AI

While Artificial Intelligence/Machine Learning models excel at pattern recognition, anomaly detection and predictive analytics, relying on them alone for precise data aggregation can potentially lead to inconsistencies and a loss of trust in your data. We've all heard about "AI hallucinations" in LLMs—imagine that margin of error applied to your core operational metrics.

Most AI/ML models are inherently probabilistic: They identify patterns based on likelihoods, not certainties. For business-critical functions, such as aggregating cloud costs or ensuring regulatory compliance, "highly likely" isn't good enough. There's a need for verifiable accuracy.

This isn't an argument against AI use for operational insights—quite the opposite. The real power lies in a hybrid approach that uses AI for what it does best (discovery, prediction, identification of opportunities) and couples it with deterministic implementations for what must be precise (calculation, aggregation, validation).

Architecture diagram showing a Financial Ledger processing through a Deterministic Calculation Layer and AI/ML Discovery Layer to produce financial insights.

Think of it as building an insight engine with two distinct but integrated components:

  • The AI/ML discovery layer sifts through vast datasets to identify anomalies, forecast trends, categorize unstructured system logs, and surface optimization opportunities. It answers "what to look at" and "why it might be happening."
  • The deterministic calculation layer takes the AI's outputs and executes precise, rule-based, verifiable computations. This is where performance metrics are summed and compliance checks run with accuracy.

This architecture ensures that while we benefit from AI surfacing complex insights, the underlying core business metrics remain unassailable.

Implementing deterministic wrappers

The key to operationalizing this hybrid approach is designing systems with clear boundaries so that any data requiring absolute precision passes through a deterministic engine—a deterministic wrapper around the AI's insights.

Consider a simplified example: An AI model identifies spending categories from raw, unstructured invoice data (e.g., "Cloud Compute," "Software Licenses"). The AI is excellent at that categorization—a probabilistic task—but we wouldn't want it to sum the costs. Instead, its categorized output feeds into a deterministic aggregation process, shown below.

import pandas as pd

  # --- Step 1: Simulated AI/ML Output (Probabilistic Layer) ---
  # In a real scenario, this would come from an NLP model classifying invoice descriptions.
  ai_classified_transactions = pd.DataFrame({
      'transaction_id': [101, 102, 103, 104, 105],
      'description': ["AWS EC2 usage Q1", "Salesforce licenses", "Azure VM costs", "Datadog monitoring", "GCP storage Q1"],
      'identified_category': ["Cloud Compute", "Software Licenses", "Cloud Compute", "Software Licenses", "Cloud Compute"],
      'amount': [12500.50, 4500.00, 8900.75, 1200.25, 3000.00],
      'confidence_score': [0.98, 0.95, 0.97, 0.92, 0.96]  # AI's confidence in classification
  })

  # --- Step 2: Deterministic Calculation Layer (The Wrapper) ---
  def get_deterministic_category_spend(transactions_df: pd.DataFrame) -> pd.DataFrame:
      """Aggregates spend by category using deterministic, always-repeatable sums."""
      if transactions_df.empty:
          return pd.DataFrame(columns=['category', 'total_spend'])
      aggregated_spend = transactions_df.groupby('identified_category')['amount'].sum().reset_index()
      aggregated_spend.columns = ['category', 'total_spend']
      if (aggregated_spend['total_spend'] < 0).any():
          print("Warning: Negative spend detected in aggregation. Investigate data quality.")
      return aggregated_spend

  final_category_spend = get_deterministic_category_spend(ai_classified_transactions)

  # --- Step 3: The AI Narrative Layer (Probabilistic) ---
  def generate_ai_commentary(deterministic_data: pd.DataFrame):
      """Sends accurate data back to an AI to generate natural-language insights."""
      top = deterministic_data.iloc[0]
      return (
          f"Insight: Your highest spend category is '{top['category']}' at ${top['total_spend']:,.2f}. "
          "Recommendation: Cloud Compute shows a 12% MoM increase. "
          "Consider reviewing idle EC2 instances in the Dev environment."
      )

  report_insight = generate_ai_commentary(final_category_spend)

The pattern forms a "sandwich" architecture:

The probabilistic start: The AI's role (ai_classified_transactions) is to interpret and categorize unstructured data.

The deterministic core: The core layer (get_deterministic_category_spend) acts as ground truth, performing the nonnegotiable task of summing numerical values with absolute precision, always producing the same correct total.

The probabilistic finish: The final step (generate_ai_commentary) takes that accurate data and produces a natural-language narrative, so stakeholders get a human-readable insight backed by audited numbers.

Why this approach matters

Trust and reliability: When business-critical decisions are on the line, certainty trumps probability. Separating math from interpretation ensures the bottom line is always correct.

Auditability: Deterministic calculations are inherently auditable. Every metric can be traced to its source, which is essential for compliance, operational governance and post-incident reviews.

Clearer problem isolation: If an insight feels off, you can immediately tell whether the issue is a categorization error (AI), a logic error (code) or a narrative error (AI).

Strategic AI application: AI does what it's best at—pattern recognition and communication—while arithmetic stays with the systems designed for it.

Key takeaways

Embrace the sandwich architecture: Use AI for discovery, deterministic code for calculation and AI again for summary.

Identify "deterministic by design" requirements: Before building, ask which parts of an insight must be verifiable. Those are candidates for hard-coded logic.

Treat AI as a consultant, not a calculator: Let AI suggest the "what" and "why," but never let it be the final word on "how much."

Build trust through transparency: Keep deterministic logic clear and auditable so that stakeholders know the foundation of their insights is solid.

By thoughtfully integrating deterministic implementations into AI/ML-driven insight generation, we can build more robust, reliable and trustworthy systems that empower better decision-making across Capital One Tech.


Vikram Mohanagandhi
Vikram Mohanagandhi, Distinguished Engineer, CT - Mainstreet

Vikram Mohanagandhi is a distinguished engineer on Capital One's CT Mainstreet team, with over 18 years of experience architecting large-scale financial systems. He led the design of the insights engine powering CreditWise's spend analyzer, building a unified rules engine and batch/real-time pipelines that turn raw transaction data into personalized, actionable guidance for millions of customers. Vikram has also served as solution architect for core card-processing platforms handling Capital One's entire 180+ million customer base and has driven enterprise-scale integration and cloud-migration initiatives. He is an AWS Certified Solutions Architect who is passionate about building deterministic, trustworthy AI systems for financial decisioning.