đŸ©č Self-Healing Code — try_ai Fixes Runtime Errors with AI Pipe's new try_ai syntax catches runtime errors and uses an LLM to repair and re-execute the broken expression, with a catch block as a final fallback. In an example, the type error "42" * 3 was automatically fixed to (to_num "42") * 3, returning 126, while healthy code like 6 * 7 runs without any API call. The feature is part of the Pipe in 30 Lines series and requires a DeepSeek API key to run. ← All posts← Alle BeitrĂ€ge ../blog.html đŸ©č Self-Healing Code — try ai Fixes Runtime Errors with AI A type error that repairs itself: try ai catches the crash, asks the LLM to fix the expression, and re-runs it. Part of the Pipe in 30 Lines series: RAG without a vector DB tutorial-local-rag.html · Parallel LLM calls tutorial-parallel.html · Your first MCP server tutorial-first-mcp-server.html "42" 3 is a type error — a string multiplied by a number. Most runtimes crash. Pipe's try ai catches the error, sends the broken expression to the LLM, and re-runs the repaired code. The catch block only fires if even the AI can't fix it. ai provider "deepseek" result: try ai "42" 3 -- E002 type error → AI repairs it catch e 0 -- only reached if the fix fails print result -- 126 fast: try ai 6 7 -- healthy code: zero API calls catch e -1 print fast -- 42 What happens here: runs the block. On success it returns the value directly — try ai no API call, no latency . The safety net is free.- On a runtime error it asks the LLM to repair the broken expression: "42" 3 becomes to num "42" 3 and re-runs. - The block is the final fallback — your pipeline never dies silently. catch This is where a language boundary pays off: try ai isn't a library that wraps your calls, it's syntax that can rewrite and re-execute a fragment of your own program . That's self-healing infrastructure — not an SDK callback. try ai E002 | attempt 1 | ""42" 3" → " to num "42" 3" | ✓ FIXED 126 42 Run it: export DEEPSEEK API KEY=... && pipe -vm -q examples/blog try ai.pipe . The deeper mechanics including the sandboxed re-run profile are covered in the MCP Cell deep dive mcp-cell.html . đŸ©č Selbstheilender Code — try ai repariert Laufzeitfehler mit KI Ein Typfehler, der sich selbst repariert: try ai fĂ€ngt den Crash, lĂ€sst das LLM den Ausdruck fixen und fĂŒhrt ihn erneut aus. Teil der Serie Pipe in 30 Lines : RAG ohne Vektor-DB tutorial-local-rag.html · Parallele LLM-Calls tutorial-parallel.html · Dein erster MCP-Server tutorial-first-mcp-server.html "42" 3 ist ein Typfehler — ein String mal eine Zahl. Die meisten Runtimes crashen. Pipes try ai fĂ€ngt den Fehler, schickt den kaputten Ausdruck an das LLM und fĂŒhrt den reparierten Code erneut aus. Der catch -Block feuert nur, wenn selbst die KI es nicht hinbekommt. ai provider "deepseek" result: try ai "42" 3 -- E002 Typfehler → KI repariert ihn catch e 0 -- wird nur erreicht, wenn der Fix scheitert print result -- 126 fast: try ai 6 7 -- gesunder Code: null API-Calls catch e -1 print fast -- 42 Was hier passiert: fĂŒhrt den Block aus. Bei Erfolg liefert es den Wert direkt — try ai kein API-Call, keine Latenz . Das Sicherheitsnetz ist kostenlos.- Bei einem Laufzeitfehler bittet es das LLM, den Ausdruck zu reparieren: aus "42" 3 wird to num "42" 3 , dann wird erneut ausgefĂŒhrt. - Der -Block ist die letzte Absicherung — deine Pipeline stirbt nie still. catch Hier zahlt sich die Sprachgrenze aus: try ai ist keine Bibliothek, die deine Calls umwickelt, sondern Syntax, die ein Fragment deines eigenen Programms umschreiben und neu ausfĂŒhren kann. Selbstheilende Infrastruktur — kein SDK-Callback. try ai E002 | attempt 1 | ""42" 3" → " to num "42" 3" | ✓ FIXED 126 42 Starten: export DEEPSEEK API KEY=... && pipe -vm -q examples/blog try ai.pipe . Die tieferen Mechanismen inkl. des sandboxed Re-Run-Profils findest du im MCP-Cell-Deep-Dive mcp-cell.html .