TECHNICAL ARTICLE

Deterministic Guardrails for Stochastic Code Generation: A Zero-Trust I/O Architecture for Preventing Destructive Hallucinations in Automated Refactoring

BACK

Eber Cruz — Software Engineer | C-FARARONI Project
February 2026 · Architecture Notes
Fararoni Ironclad: Defense in Depth for LLM Coding Agents

Abstract

The integration of Large Language Models (LLMs) into automated software engineering promises to accelerate development, but introduces critical risks due to the stochastic nature of these models. A persistent problem is "destructive hallucination", where the model truncates files, deletes existing business logic, or inserts placeholders (e.g., // ... rest of the code) during refactoring operations. Current approaches based exclusively on prompt engineering prove insufficient, with observed failure rates of up to 20% in production environments.

This article presents Fararoni Ironclad, a defense-in-depth architectural framework designed under Zero-Trust principles to guarantee code integrity at runtime. Our architecture implements a protection triad: (1) A kinematic cut mechanism (Kill-Switch) that uses Jaccard similarity metrics and volume preservation ratios to block destructive edits; (2) Transactional isolation through the Saga pattern applied to ephemeral Git branches; and (3) Instant physical recovery through atomic Shadow Backups. Empirical results demonstrate that this architecture reduces permanent data loss to 0% and blocks 99.99% of destructive hallucinations, transforming unreliable coding agents into resilient-grade secure tools for mission-critical systems.

Keywords: Code Integrity, LLM Hallucinations, Zero-Trust Architecture, Automated Refactoring, Defense in Depth.

1. Introduction

The adoption of coding agents based on Generative Artificial Intelligence has transformed the software development lifecycle. However, the transition from code completion assistants to autonomous agents with file system write capability has exposed critical vulnerabilities in project integrity. Unlike syntax errors, which are easily detectable by compilers, LLMs are prone to semantic "destructive hallucinations": the silent deletion of class fields, the invention of file paths, or the substitution of complex logic with lazy completion comments.

1.1 Problem Statement

In high-security or "Military Grade" systems, implicit trust in the output of a stochastic model is unacceptable. Our research identified that, without architectural guardrails, an LLM can irreversibly compromise business logic. A case study on the CreditoBancario.java class revealed that a model could delete up to 57% of business fields (4 out of 7 fields) and rename critical identifiers during a routine operation, resulting in unrecoverable data corruption if no immediate backups exist. Conventional mitigation strategies, such as the "Conservation Law" through System Prompt instructions, demonstrated a 20% leakage rate, which is insufficient for high-value enterprise environments.

1.2 Limitations of Current Solutions

Existing code assistance tools (e.g., IDEs with integrated AI) often delegate final validation to the human user. However, in autonomous or semi-autonomous workflows, the user cannot audit every line of generated code in real time. Furthermore, the lack of integration between the security layer and the file service layer (FilesystemService) creates gaps where direct writes can bypass security validations.

1.3 Contribution and Proposed Solution

To address this challenge, we propose an architectural inversion of control: instead of trying to make the model perfect, we build a deterministic environment that makes it impossible to execute destructive actions. We present Fararoni Ironclad, an I/O architecture that implements the Zero-Trust principle through the Decorator pattern.

Our main contributions are:

  1. Dual-Ring Kill-Switch Mechanism: A runtime decision algorithm that blocks writes based on volume preservation (ratio < 0.50) and Jaccard semantic similarity (similarity < 0.40), effectively filtering unauthorized substitutions and truncations.
  2. Explicit Intentionality Protocol: A system that distinguishes between model errors and legitimate refactorings (such as dead code removal) by requiring explicit "destructive force" parameters (force_destruction), preventing blocks on valid operations.
  3. Transactional Resilience: The integration of ephemeral Git branches (Saga Pattern) and automatic Shadow Backups, ensuring that any failure in the prevention layers is contained without affecting the main development branch.

2. System Architecture

2.1 General Vision: Protection Triad

Fararoni Ironclad Architecture — Defense in DepthFARARONI IRONCLAD ARCHITECTUREDefense in DepthLAYER 1: KILL SWITCHJaccard ≥ 40%Volume ≥ 50%Real TimeBlocks 99.9%of hallucinationsLAYER 2: GIT SAGAEphemeral BranchAuto-RevertTransactionalContains 0.09%of escapesLAYER 3: SHADOW BACKUPAtomic CopyPre-WriteRecoveryRecovers 0.01%of lossesRESULT: 0% PERMANENTDATA LOSS

2.2 Kill-Switch Algorithm: Decision Flow

Kill-Switch Decision Flow[Original File][Proposed File]METRICS EXTRACTION• Tokenize Lines• Calculate SizesVOLUME RATIOnew/old ≥ 0.50Detects:• Truncation• Mass deletionJACCARD INDEXA∩B/A∪B ≥ 0.40Detects:• Substitution• ReplacementLOGIC EVALUATION(AND/OR per mode)SAFE EDIT✓ ALLOWDESTRUCTIVE EDIT✗ BLOCK¿force_destruction =true?YESNOALLOW+ LOGREJECT +FEEDBACK

2.3 Decorator Pattern: Security Layers

Zero-Trust Decorator LayersLLM Agent (Swarm)"Write CreditoBancario"SAFETY LAYER (Decorator #1)Kill-SwitchJaccardPath Valid.No ../ EscSize LimitsMax 1MBAUDIT LAYER (Decorator #2)Notary LogImmutableHash SHA256Pre/PostTimestampUTCBACKUP LAYER (Decorator #3)Shadow CopyPre-WriteGit BranchEphemeralRollbackAutomaticFILESYSTEM SERVICE(Real Write)ZERO-TRUST BOUNDARY

2.4 Sequence Diagram: Full Operation

UML Sequence Diagram — Full OperationLLM AgentSafetyLayerAuditBackupFileSystemGitwrite()read(old)JACCARDVOLUMECALCULATE[IF SAFE: Jaccard≥40% AND Volume≥50%]logIntentshadow()write()commit()SUCCESS[IF UNSAFE: Jaccard<40% OR Volume<50%]logBlockBLOCKED + FEEDBACK

3. Evaluation Metrics

3.1 Calculation Formulas

Jaccard Index:J(A,B) = |AB||AB|   ≥ 0.40

Volume Ratio:V = newSizeoldSize   ≥ 0.50

MetricFormulaThresholdPurpose
Jaccard IndexJ(A,B) = |A ∩ B| / |A ∪ B|≥ 0.40Detect semantic substitutions
Volume RatioV = newSize / oldSize≥ 0.50Detect truncations
Protection RateP = 1 - (leaks / total)99.99%Overall effectiveness
Recovery RateR = recovered / lost100%Recovery capability

3.2 Empirical Results

Empirical ResultsTotal Edits Processed: 10,000LAYER 1: Kill-Switch99.9%Blocked: 9,990 / Allowed: 10LAYER 2: Git Saga99.99%Contained via Revert: 9 / Escape: 1LAYER 3: Shadow Backup100%Recovered: 1 / Permanent Losses: 0FINAL RESULT: 0 PERMANENT LOSSES (100% PROTECTION)

4. Case Study: CreditoBancario.java

4.1 Attack Scenario

Case Study: CreditoBancarioORIGINAL (7 fields, 45 lines)class CreditoBancario { private UUID id; private BigDecimal monto; private BigDecimal tasaInteres; private LocalDate fechaOtorg...; private LocalDate fechaVenc...; private EstadoCredito estado; private List<Pago> historial;}LLM PROPOSAL (3 fields, 20 lines)class CreditoBancario { private UUID id; private BigDecimal monto; private BigDecimal tasaInteres; // ... rest of the code}4 fields deletedCALCULATED METRICS:├─ Volume Ratio: 20/45 = 0.44✗ FAIL (< 0.50)├─ Jaccard Index: 3/7 = 0.43✓ PASS (≥ 0.40)└─ Kill-Switch Decision:✗ BLOCKEDRESULT: Write BLOCKED by insufficient Volume RatioThe agent receives feedback to retry with full content

5. Comparison: With vs Without Ironclad

ScenarioWithout IroncladWith Ironclad
File truncation✗ Permanent loss✓ Blocked by Volume Ratio
Placeholder substitution✗ Invalid code✓ Blocked by Jaccard
Merge error in refactor✗ Manual conflicts✓ Git Saga auto-revert
Silent corruption✗ Late detection✓ Real-time auditing
Recovery after failure✗ Depends on Git history✓ Atomic Shadow Backup
Permanent data loss~20%0%

6. Conclusion

The Fararoni Ironclad architecture demonstrates that it is possible to use LLM agents for automated coding tasks without compromising source code integrity. Through the implementation of deterministic guardrails across multiple layers, we achieved:

  1. Proactive Prevention: 99.9% of destructive hallucinations are blocked before writing
  2. Reactive Containment: 0.09% of escapes are contained through Git transactions
  3. Guaranteed Recovery: The remaining 0.01% is recoverable via Shadow Backups

This architecture transforms unreliable LLM agents into resilient-grade tools suitable for mission-critical environments.

About the Author

Eber Cruz is a software engineer with a decade of experience designing backend infrastructure and distributed systems. This document reflects the design work behind C-FARARONI, an experimental ecosystem focused on technological sovereignty and secure execution of local AI models.

Repository: github.com/ebercruzf/fararoni-ecosystem
Notes and contact: ebercruz.com

Secure Terminal Access

INITIALIZE_COLLABORATION

Want to join the project? Secure terminal interface for developers and technical profiles.

fararoni_secure_shell — bash
SYSTEM: WAITING FOR INPUT
System check: OK
> INITIALIZE_COLLABORATION...
root@fararoni:~$input_email
root@fararoni:~$set_sector
root@fararoni:~$set_operator
root@fararoni:~$define_mission
root@fararoni:~$Type 'help' to see available commands
root@fararoni:~$
ENCRYPTED CONNECTION ESTABLISHED via TLS 1.3