Skip to content
Threadbull

// Threadbull Engineering

Untangling the AI mess.

AI can write code. We make it work. Threadbull audits, refactors, and hardens AI-generated codebases — and builds deterministic AI workflows with tight schemas, explicit state, and predictable execution.

~40 yrs engineering · 30+ shipped games · custom 3D engines · C++ / systems / agents

// Symptoms

It worked in the demo.

  • Every fix breaks two other things.
  • The app slows to a crawl as real data arrives.
  • Nobody — including the AI — understands the codebase anymore.
  • Your agent loops, retries forever, or writes garbage to the database.
  • Your token bill doubled and you can't say why.
  • You're worried about what a security review would find.

These aren't prompt problems. They're engineering problems.

Three ways we help.

// How we think

Less magic. More engineering.

Most AI shops add more AI to fix AI. Threadbull adds engineering: tight schemas, explicit state machines, validation at every boundary, tests, and the minimum agent surface area needed to do the job.

01

Deterministic by default.

If a step can be code, it's code. Models handle judgment, not plumbing.

02

Validate every boundary.

Every model output is parsed against a schema before it touches your data. Invalid output fails loudly, not silently.

03

Minimal agent surface.

Fewer agents, fewer tools, tighter permissions. Complexity is a cost, not a feature.

04

Leave it better than a black box.

Tests, docs, and a handoff your team (or your next AI tool) can actually work from.

// The difference

Same feature. Different engineering.

before.py — typical AI-generated agent loop
# Agent decides what to do and writes straight to the DB
def process_ticket(ticket):
    while True:
        resp = llm.chat(f"Handle this support ticket and return JSON: {ticket}")
        try:
            data = json.loads(resp[resp.find("{"):resp.rfind("}") + 1])
        except Exception:
            continue  # just ask again...forever
        if data.get("action") == "refund":
            db.execute(f"UPDATE orders SET refunded=1 WHERE id={data['order_id']}")
        if data.get("done"):
            break
  • unbounded loop
  • string-sliced JSON
  • swallowed errors
  • SQL injection
  • model can issue refunds
  • no audit trail
after.py — deterministic pipeline
from enum import Enum
from pydantic import BaseModel, Field, ValidationError

class Action(str, Enum):
    REPLY = "reply"
    ESCALATE = "escalate"
    REQUEST_REFUND = "request_refund"   # proposes; never executes

class TicketDecision(BaseModel):
    action: Action
    order_id: int | None = Field(default=None, gt=0)
    reply_text: str = Field(max_length=2000)
    confidence: float = Field(ge=0, le=1)

MAX_ATTEMPTS = 2

def classify_ticket(ticket: Ticket) -> TicketDecision:
    for attempt in range(MAX_ATTEMPTS):
        raw = llm.structured(TICKET_PROMPT, ticket.text, schema=TicketDecision)
        try:
            return TicketDecision.model_validate_json(raw)
        except ValidationError as err:
            log.warning("invalid_llm_output", attempt=attempt, error=str(err))
    return TicketDecision(action=Action.ESCALATE, reply_text="", confidence=0.0)

def process_ticket(ticket: Ticket) -> None:
    decision = classify_ticket(ticket)
    audit.record(ticket.id, decision)                 # every decision is logged
    if decision.action is Action.REQUEST_REFUND:
        refunds.queue_for_review(ticket.id, decision.order_id)  # human-in-the-loop
    elif decision.action is Action.REPLY and decision.confidence >= 0.8:
        replies.send(ticket.id, decision.reply_text)
    else:
        escalations.open(ticket.id, decision)
  • bounded retries
  • schema-validated
  • typed actions
  • parameterized writes
  • human approval for money
  • full audit log
Illustrative example of a common pattern we fix.

// Start here

Start with a 15-hour Technical Audit.

A fixed-scope, fixed-price review of your codebase or AI pipeline. You get a written report and a walkthrough call. You'll know exactly what's wrong, what it's costing you, and what to fix first — whether or not you hire us for the fix.

Fixed price: $2,000 — founding-client rate (list $3,500). Credited toward any follow-on engagement.

Not ready for a full audit? Start with a 90-minute Code Triage for $399.

audit --scope fullWhat you get
  • Architecture and dependency map
  • Security review (auth, access control, secrets, injection, data exposure)
  • Performance and cost hotspots (including LLM token spend)
  • Reliability review of AI components (loops, parsing, retries, failure modes)
  • Prioritized fix plan with effort estimates
  • 60-minute walkthrough call

You work directly with a senior engineer.

Threadbull is led by Dan Duncalf, a software engineer with nearly 40 years of experience. He co-founded Pipeworks Software in 1999, shipped more than 30 commercial video games, and built multiple proprietary 3D engines — work where performance, memory, and reliability are not optional. Today he applies that same discipline to AI systems and the code AI writes.

More about Dan →

Your code is telling you something. Let's read it.