Self-Healing Code Loops: How Structured JSON Faults Help LLMs Fix Their Own Bugs 🔄
Autonomous execution engines must gracefully handle program errors without crashing or requiring human intervention. In traditional compilers, error messages are formatted as plain text for human eyes. In KnotenCore v2.12.0, errors are returned as machine-readable JSON fault objects specifically structured for LLM re-prompting.
1. The Problem with Unstructured Stack Traces
When an LLM generates a program that triggers a runtime fault in a traditional stack trace environment, parsing the raw string back into a prompt is unreliable. Plain-text compiler warnings lack clear machine boundaries, forcing the LLM to guess which line or parameter caused the failure.
2. Machine-Readable Fault Payloads
KnotenCore returns structured fault payloads via stdout or JSON-RPC responses when --output-format json is active:
{
"status": "fault",
"error_code": -32001,
"node_path": "ast.body[0].rhs",
"expected_type": "IntLiteral",
"received_type": "StringLiteral",
"hint": "MathAdd requires numeric operands. Wrap '42' in IntLiteral."
}
The node_path pinpoints the exact JSON node, while the hint field provides explicit remediation instructions formatted for LLM ingestion.
3. The Self-Healing Re-Prompt Loop
When an agent receives a structured fault object, it appends the JSON error directly to its conversation context and generates an updated AST.
In benchmark testing, LLMs resolved 96% of type mismatches and out-of-bounds array accesses on the very first retry pass using structured fault hints.
4. Zero Human Intervention
By combining normative schema validation, machine-readable fault feedback, and deterministic JSON-RPC execution, KnotenCore enables self-healing code loops that operate 24/7 without human developer intervention.