Research Motivation

Sentinel-Mesh started from an engineering observation, not a literature review. While building the 28K+ record AI enrichment pipeline at TechPotion, I noticed a recurring reliability limitation in the translation and enrichment stage. Most outputs succeeded, but some repeatedly failed and needed retries, and in some cases the model returned malformed JSON even though the task was tightly constrained. Roughly 2 in 10 outputs hit one of these problems. That was a rough observation from that pipeline, and it fluctuated with model and load. It is not a general AI failure rate.

Why Structured-Output Reliability Matters

In that pipeline, the fix was engineering discipline: schema-checked outputs, and status gates that keep a failed record visible and retryable instead of silently marking it done. A schema check can tell you an output is well-formed. It can't tell you the output is correct.

The Cloud-Security Question

That gap matters much more when the output is a change to cloud infrastructure. A Terraform patch can be syntactically valid and still leave a storage bucket public, drop encryption, or open a security group to the internet. The experience raised a broader question: if a model can't consistently produce valid structured output for a bounded task, how should AI-generated changes be trusted when the consequences involve cloud security?

Research Question

Can an LLM's proposed remediation for a Terraform misconfiguration be accepted only when a formal verifier shows it satisfies explicit security invariants, and does feeding the verifier's rejection back to the model improve repair rates?

Sentinel-Mesh explores that by combining three things: LLM remediation generation, Z3 SMT formal verification, and Terraform remediation, in a single closed loop.

Architecture

  1. Parsing. Terraform HCL is converted to a JSON structure with python-hcl2.
  2. Initial verification. A Z3-based verifier checks every resource. Per-resource security checks are encoded as Z3 queries over the Cloud Perimeter Model (CPM), which covers network isolation, encryption at rest and in transit, and defense in depth. Dedicated Z3 reachability checks look for IAM privilege-escalation paths and security groups that expose critical ports. A configuration that passes needs no patch.
  3. Patch generation. On a violation, an LLM agent receives the original configuration and the verifier's violation message, and proposes a remediated configuration.
  4. Patch verification. The HCL is extracted from the model response, re-parsed, and checked again by the full verifier. That re-check alone decides whether the patch passes.
  5. Feedback loop. A rejected patch's verdict becomes the context for the next attempt, for up to 5 attempts. A case with no verified patch after 5 attempts is recorded as a persistent failure.
  6. Proof certificate. For encryption and network-exposure violations, an accepted patch also goes through a dual-solver refinement proof over the CPM. The proof annotates the result; it never overrides the verifier's decision.
Sentinel-Mesh closed-loop remediation and evaluationA Terraform configuration is parsed to JSON with python-hcl2 and checked by a Z3 verifier: per-resource checks over the Cloud Perimeter Model plus IAM escalation and network reachability checks. Secure configurations stop there. On a violation, an LLM remediation agent rotating across Cerebras, Gemini, and Groq proposes a patch, which is extracted, re-parsed, and re-checked by the full verifier, which alone decides pass or fail. Rejections are fed back to the LLM for up to five attempts. For encryption and network violations, an accepted patch also gets a dual-solver proof certificate. An experiment runner evaluates the loop on 105 CloudFix-Bench cases alongside a Checkov baseline, a no-witness ablation, and a 12-case external set.Terraform configCloudFix-Bench caseHCL parserpython-hcl2 → JSONZ3 verifierCloud Perimeter Model checksIAM + network reachabilityAlready secureno patch neededClosed repair loop · up to 5 attemptsviolation + witnessLLM remediation agentCerebras · Gemini · Groqprovider rotationCandidate HCL patchextracted from fenced blockre-parsed to JSONRe-verify patch (Z3)full verifier re-rundecides pass or failrejected · verdict fed backPersistent failureno verified patch in 5 attemptsProof certificatedual-solver CPM proofencryption / network casesFixedverified patch acceptedpassEvaluationExperiment runner105 CloudFix-Bench casesBaselines & ablationCheckov · no-witness ablationexternal set (12 cases)ResultsWilson 95% intervals
Simplified view of the Sentinel-Mesh loop. The LLM only proposes patches; the verifier decides. A pass is formal within the Cloud Perimeter Model scope, not a claim of overall security.

LLM Remediation Generation

Patch generation is zero-shot and multi-provider: the agent supports Cerebras, Gemini, and Groq backends, rotating across providers with cooldowns to handle rate limits. The model only proposes; it never decides whether its own patch is acceptable. Responses are normalized by extracting the fenced HCL block, so conversational text around the code can't reach the verifier.

Formal Verification with Z3 SMT

Security properties are encoded as Z3 constraints over the parsed configuration. When a configuration violates an invariant, the solver finds a satisfying assignment for the violation, a counterexample witness: for example, a concrete source address and port that reach a critical service, or a chain of IAM permissions that reaches administrator access. The verifier's verdict, built from that witness, is fed into the next prompt.

A candidate patch is accepted only if the full verifier passes it. For violations the CPM can model directly, encryption and network exposure, an accepted patch also gets a dual-solver refinement proof. Solver A checks completeness: that no counterexample exists, so the patched configuration satisfies the modeled invariants. Solver B checks non-regression: it uses the original configuration to confirm the violation was real, then shows that the patched configuration cannot retain that violation class. Passing both produces a formal proof certificate. Audit and policy properties, such as a missing WAF association or lifecycle policy, sit outside the CPM state space, so they are decided by the verifier alone.

Terraform Remediation

The unit of work is a real Terraform configuration: a main.tf per test case, covering resources across 8 infrastructure pillars (management, identity, database, networking, security, compute, analytics, and storage) and 60+ AWS service types. Patches are full, re-parseable configurations, not diff hints.

CloudFix-Bench

To evaluate the loop, I built CloudFix-Bench: 105 AWS Terraform misconfiguration patterns, each a self-contained Terraform case with a known violation. The benchmark is archived on Zenodo so the evaluation can be reproduced.

Evaluation

The evaluation compares the full loop against three references:

Success rates are reported with 95% Wilson score confidence intervals. The reported results:

Of the 88 fixed cases, 75 were fixed on the first attempt. Formal proof certificates were issued for 29 of the 105 cases.

Findings

Limitations

Future Work

The limitations point to the next steps: a larger external evaluation on real-world Terraform, broader invariant coverage for the pillars with the lowest repair rates, and extending proof certificates beyond the current subset of policies.

Research Artifacts

The Research Square preprint, the CloudFix-Bench dataset on Zenodo, the source code, and a technical article are linked under public evidence below, and collected on the research page. I'm the lead author and developer; the preprint is co-authored, and lists the full author team.

Related services

Related projects

Public evidence

Need something similar?

Available for remote AI automation, n8n, AI agent, API integration, and B2B SaaS QA projects.