{"slug": "deterministic-business-rules-for-ai-agents-how-neuron-js-validates-executes-and", "title": "Deterministic business rules for AI agents: how neuron-js validates, executes and explains JSON rule scripts", "summary": "SebaSOFT released neuron-js, an MIT-licensed TypeScript library that stores business rules as pure JSON ExecutionScripts, validates them before execution, and produces an ExecutionExplanation trace of which rules and conditions fired. The library is deterministic and replayable, and ships with a read-only MCP server exposing validate_script, execute_decision and explain_decision tools so agents like Claude Desktop and Cursor can operate rule sets without integration code.", "body_md": "AI agents are getting good at writing business logic. That's exactly the problem.\n\nAn agent generates a pricing rule that looks perfect: reads well, matches the\n\nrequest, even passes a quick test. But nobody can *verify* it. Can you replay\n\nyesterday's decision? Can you prove to an auditor why customer X got discount Y?\n\nCan you be sure the rule that ran is the rule that was reviewed?\n\nAt SebaSOFT we kept hitting this failure mode while building AI-driven workflow\n\nautomation, so we built [neuron-js](https://github.com/SebaSOFT/neuron-js) — an\n\nMIT-licensed TypeScript library where every rule set is pure JSON, validated\n\nbefore execution, and explained after it. This post walks through why those\n\nthree properties matter for AI workflows and how the pieces fit together.\n\nIn neuron-js, a ruleset is an **ExecutionScript**: a JSON document containing\n\nrules, and each rule contains conditions and actions. It serializes, diffs\n\ncleanly in pull requests, versions in git, and moves between environments\n\nwithout transpilation:\n\n```\n{\n  \"id\": \"volume-discount\",\n  \"rules\": [\n    {\n      \"id\": \"discount-rule\",\n      \"type\": \"simple_rule\",\n      \"options\": {},\n      \"conditions\": [\n        {\n          \"id\": \"quantity-check\",\n          \"type\": \"compare_two_numbers\",\n          \"options\": {},\n          \"params\": [\n            { \"id\": \"p1\", \"name\": \"op1\", \"type\": \"simple_number\", \"value\": \"${quantity}\", \"options\": {} },\n            { \"id\": \"p2\", \"name\": \"comp\", \"type\": \"comparator\", \"value\": \">\", \"options\": {} },\n            { \"id\": \"p3\", \"name\": \"op2\", \"type\": \"simple_number\", \"value\": \"100\", \"options\": {} }\n          ]\n        }\n      ],\n      \"actions\": [\n        {\n          \"id\": \"apply-discount\",\n          \"type\": \"add_two_numbers\",\n          \"options\": {},\n          \"params\": [\n            { \"id\": \"a1\", \"name\": \"op1\", \"type\": \"simple_number\", \"value\": \"${price}\", \"options\": {} },\n            { \"id\": \"a2\", \"name\": \"op2\", \"type\": \"simple_number\", \"value\": \"-10\", \"options\": {} }\n          ]\n        }\n      ]\n    }\n  ]\n}\n```\n\nTwo components make this run:\n\nBecause logic lives in data, an AI agent can *author* rules — and because the\n\nschema is strict, whatever the agent writes gets machine-validated before it\n\ncan touch anything real.\n\nEvery execution path validates first:\n\n``` js\nimport { Neuron, Synapse, validateScript } from \"@sebasoft/neuron-js\";\n\nconst validation = validateScript(scriptJson);\nif (!validation.ok) {\n  // exact errors, nothing executed — ever\n  console.error(validation.errors);\n} else {\n  const result = new Synapse(new Neuron()).execute(scriptJson, context);\n}\n```\n\nAn invalid script never executes. It returns the exact validation errors\n\ninstead of a half-evaluated result. This is the property that makes\n\nAI-generated rules auditable: the schema is the contract, and the contract\n\nis enforced by the runtime, not by convention.\n\nEvery run can produce an **ExecutionExplanation**: which rules matched, which\n\nconditions evaluated true or false, and in what order. For compliance and\n\ndebugging this changes the conversation from \"trust the engine\" to \"here is\n\nthe trace of decision #4821.\"\n\nCombined with determinism — same script, same context, same output, every\n\ntime — you get replayability: store script + context, replay any decision\n\nexactly, prove the outcome matches the trace.\n\nThe piece that connects all of this to AI agents is the bundled\n\n[MCP server](https://github.com/SebaSOFT/neuron-js/tree/main/examples/mcp-server).\n\nClaude Desktop, Cursor, or any MCP client can register three tools —\n\n`validate_script`, `execute_decision`, `explain_decision` — and operate rule\n\nsets without writing integration code:\n\n```\n{\n  \"mcpServers\": {\n    \"neuron-js\": {\n      \"command\": \"node\",\n      \"args\": [\"/absolute/path/to/neuron-js/examples/mcp-server/run.ts\"]\n    }\n  }\n}\n```\n\nThe server is read-only and deterministic. Every tool call validates its\n\ninputs first (fail-closed again) and returns JSON. An agent can validate a\n\nrule it just wrote *before* proposing it, execute it against test contexts,\n\nand explain the result — the full authoring loop.\n\nOur [benchmark harness](https://sebasoft.github.io/neuron-js/benchmarks/results.html)\n\ncompares neuron-js against json-rules-engine, json-logic-js, node-rules and\n\nhand-coded TypeScript across three scenarios (pricing, eligibility, routing)\n\nand three input sizes. On Node 24, `yarn benchmark` reproduces every number:\n\nThe fairness gates and full methodology are in the repo. If a number looks\n\nwrong, the harness prints it — file an issue.\n\nBecause the primary reader of this documentation is often an agent, the site\n\npractices what it preaches: an `llms.txt` router with a full-text variant,\n\nMarkdown mirrors of every page served at the same URLs (`rel=\"alternate\"`), MCP tools exposed on the site itself, and a\n\ntype=\"text/markdown\"\n\n`robots.txt` that explicitly welcomes AI crawlers and fetchers.\n\nThe result is a discovery loop that matches the product: an agent can find\n\nneuron-js through a search, read its documentation in clean Markdown, register\n\nits MCP server, validate a rule, execute it, and explain the outcome —\n\nend-to-end without a human in the middle. The human shows up at the review\n\nstep, which is exactly where the schema guarantees your leverage.\n\nQuestions about the benchmark methodology, the MCP integration, or the\n\nvalidation schema? Happy to go deeper in the comments.", "url": "https://wpnews.pro/news/deterministic-business-rules-for-ai-agents-how-neuron-js-validates-executes-and", "canonical_source": "https://dev.to/sebasoft/deterministic-business-rules-for-ai-agents-how-neuron-js-validates-executes-and-explains-json-3ojb", "published_at": "2026-09-29 03:07:58+00:00", "updated_at": "2026-09-29 03:16:42.929965+00:00", "lang": "en", "topics": ["ai-agents", "agent-protocols", "developer-tools", "ai-tools"], "entities": ["SebaSOFT", "neuron-js", "Claude Desktop", "Cursor", "MCP"], "also_reported_by": [], "alternates": {"html": "https://wpnews.pro/news/deterministic-business-rules-for-ai-agents-how-neuron-js-validates-executes-and", "markdown": "https://wpnews.pro/news/deterministic-business-rules-for-ai-agents-how-neuron-js-validates-executes-and.md", "text": "https://wpnews.pro/news/deterministic-business-rules-for-ai-agents-how-neuron-js-validates-executes-and.txt", "jsonld": "https://wpnews.pro/news/deterministic-business-rules-for-ai-agents-how-neuron-js-validates-executes-and.jsonld"}}