Skip to content

3.7 Semantic Kernel for Audit-Analysis Programs

Editorial context, 2026-04-20: The questions, constraints, proposals, disagreements, and caveats below are reformulated from the saved research discussion. LLM recommendations remain attributed proposals, not decisions by the author or independently verified findings. Technical examples and quoted source passages retain their original wording.

The working interpretation is that this can be a strong architecture if the separate component is the semantic kernel of the system, not just another workflow service. It should define what a valid audit program is, type-check it, apply policies, and compile it into an executable plan.

The working interpretation is that this could be the right long-term architecture.

The strongest version is:

                 Semantic kernel
              Haskell / Scala / etc.
                       │
          ┌────────────┼─────────────┐
          │            │             │
      type model      DSL         policies
          │            │             │
          └────────────┼─────────────┘
                       ↓
                 validated AST
                       ↓
                    planner
                       ↓
               executable IR
                       ↓
              workflow runtime

The kernel becomes the authority on what a valid audit-analysis program means.

What belongs in the kernel

The recommendation is not to center it around Step.

The proposal is to start with concepts such as:

Procedure
Objective
Artifact<T>
Evidence<T>
Dataset<T>
Transformation<I, O>
Analysis<I, O>
ClaimSet<T>
Reconciliation<A, B>
Property<T>
Policy
Review<T>
Deliverable<T>

Then something like:

Evidence<RevenueTransactions>
        ↓
Transformation
        ↓
Dataset<MonthlyRevenue>
        ↓
Comparison
        ↓
ClaimSet<RevenueFinding>
        ↓
Review
        ↓
ReportSection<Revenue>

The language describes relationships between typed things.

The compiler can derive the operational steps later.

Where a language such as Haskell becomes useful

Haskell would let you define a fairly strong algebra.

Conceptually:

data Artifact a

data Method i o where
  Transform ::
    Transformation i o ->
    Method (Artifact i) (Artifact o)

  Analyze ::
    AnalysisSpec i o ->
    Method (Artifact i) (Artifact o)

  Review ::
    ReviewPolicy a ->
    Method (Artifact a) (Reviewed a)

Then invalid compositions become impossible or produce compile-time/domain-validation errors:

JournalEntries
   ↓ RevenueAnalysis       ← invalid input

RevenueDataset
   ↓ RevenueAnalysis       ← valid

You can also encode states:

ClaimSet Unreviewed
ClaimSet Reviewed

Evidence Unvalidated
Evidence Validated

So:

assembleFinalReport :
    ClaimSet Reviewed -> Report

cannot accidentally receive an unreviewed claim set.

That is much stronger than:

{
  "step": "assemble",
  "input": "whatever-string-id"
}

But don’t put every audit property into the type system

This is an important boundary.

Types are good for:

This analysis requires RevenueDataset.

This transformation produces VarianceDataset.

This report requires ReviewedFindings.

Money cannot accidentally be supplied where Percentage is expected.

Types cannot generally prove:

This evidence is relevant.

This management explanation is adequately supported.

The supplied population is actually complete.

This conclusion is appropriate.

Those depend on runtime data or auditor judgment.

So the proposal is to have:

Types
    structural correctness

Constraints / validators
    runtime properties

Policies
    organizational requirements

Evaluators
    semantic quality

Review
    professional judgment

Trying to encode all of PCAOB methodology into type-level Haskell would produce an elaborate system that is difficult to evolve.

Three proposed design levels

Something approximately like this:

                    BUILDER LANGUAGES

       relational        behavioral        authority
       Datalog-like      TLA-like          Cedar-like
             \              |                 /
              \             |                /
               ─────────────────────────────
                    SEMANTIC CORE / IR

                  types / artifacts
                  assumptions
                  guarantees
                  effects
                  capabilities
                  transitions
                  composition
                  invariants

               ─────────────────────────────
                        EXECUTION

                   Rust runtime/kernel
                          +
                    Wasm components
                          +
                 external participants

The builder might never know which underlying formalism handles which construct.

For example:

component Researcher {
    input  Question
    output Candidate<Claim>

    requires {
        read(dataset)
    }

    effects {
        generate
    }

    guarantees {
        every Claim has provenance
    }
}

while:

component Publisher {
    input Verified<Claim>
    output Publication

    requires {
        capability(publish)
    }

    effects {
        external(publish)
    }
}

Then:

Researcher |> Verify |> Publisher

The compiler/runtime can ask several separate questions:

type compatible?
effect compatible?
authority sufficient?
protocol valid?
invariants preserved?
required guarantee produced?

Different theories/languages answer different questions.

A potentially fundamental distinction

The proposal is to divide builder problems into roughly three semantic classes:

Relational problems

What is true?

Use relational logic / Datalog / SQL-like languages.

depends_on(A, B)
authorized(A, X)
derived_from(X, Y)

Behavioral problems

What may happen over time?

Use state machines / temporal logic / process models.

propose → approve → commit

including concurrency, retries, cancellation, failures, obligations.

Computational problems

How do I produce a value?

Use ordinary programming languages and generative models.

Question → Candidate<Answer>

Then authority/effects sit across these:

what may be computed
what may be observed
what may change the world

This is cleaner than asking one programming language to express all three equally well.

Proposal to keep the kernel separate from execution

Something like:

                   SEMANTIC KERNEL

DSL parser
Domain types
Type checker
Constraint checker
Policy engine
Planner
Compiler

                       ↓

                   Execution IR
                 JSON / protobuf

                       ↓

                      RUNTIME

AnalitycalReprEngine adapters
Data processing
LLM calls
Tools
Retries
Storage
Tracing

That means the proposed Haskell/Scala component doesn’t need to own AnalitycalReprEngine connections, model APIs, queues, report rendering, etc.

It can remain relatively pure:

Program + Catalog + Policies
            ↓
       ValidationResult

Program + Catalog
            ↓
       ExecutionPlan

A pure core is particularly valuable because it becomes easy to test exhaustively.

Tickloom case study

The complete semantic-model and scenario-DSL example is now in one case-study note. The following implementation roadmap resumes the original kernel design dialogue.

A further proposed design choice

Don’t make the first external DSL textual.

First build:

Domain algebra
        ↓
typed AST
        ↓
validators
        ↓
compiler

Then expose an embedded DSL from Haskell/Scala itself.

Express the four current workflows.

You’ll discover where the abstraction is wrong very quickly.

Only once that model stabilizes would the following be designed:

text DSL
JSON representation
visual editor
agent API

All four should ultimately construct the same typed program.

So the central architecture becomes:

              Humans + LLM
                   │
              textual DSL
                   │
                   ▼
UI ───────────→ Typed semantic model ←──────── Agent
                   │
                   ▼
             validate / compile
                   │
                   ▼
              execution plan
                   │
                   ▼
                 runtime

That is the proposed direction to pursue. The separate component becomes a small domain-specific programming language platform for audit analytics, with the LLM as one possible programmer of that language.

Library sources

Further reading:

  • Maguire 2018, Thinking with Types: Type-Level Programming in Haskell – section 5.2, “GADTs”: a type-safe syntax tree, data Expr a where LitInt :: Int -> Expr Int ..., whose constructors fix their result types the way Method i o fixes input and output artifacts; on the Haskell algebra sketch under audit-related