llm-shield

Zero-dependency error recovery layer for LLM SDKs.

Your Node.js app crashes with:

BadRequestError: 400 could not parse JSON body SyntaxError: Invalid JSON: EOF while parsing an object Invalid JSON in tool call arguments Failed to parse function arguments

These are not your fault. They're transient SDK / network / proxy artifacts. But they kill your pipeline.

Install

npm install @coder12-z/llm-shield

Use

import { shield } from "@coder12-z/llm-shield";
import OpenAI from "openai";

const client = new OpenAI();

const safeCall = shield(async (prompt) =>
  client.chat.completions.create({
    model: "gpt-4o-mini",
    messages: [{ role: "user", content: prompt }],
    response_format: { type: "json_object" },
  }),
  { maxRetries: 3 }
);

const res = await safeCall("Return JSON with {name: string}");

What it handles

What it does NOT do

Links

NPM · GitHub · MIT License