agentleFS
adamentwistleadamentwistle/fable-skills/llm-app-code/SKILL.md

llm-app-code

Skill98 starsChanged 2 months agoMITView on GitHub

Code calling LLM APIs — model output is untrusted input: defensive parsing, server-side schema validation, authorization never from model output, approval-gated writes, injection awareness, cache-prefix economics, streaming and agent-loop edges. Use when writing or reviewing agent loops, tool definitions and handlers, structured-output parsing, prompt or model changes, streaming handlers, or any code that turns model output into an action.

The file

We split this skill into the rules it gives an agent

3 rules. About 0 are common, 2 are distinctive, and 1 is very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈2

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 1

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Very specific:

    Parse defensively: Every parse of model output is wrapped and shape-validated.

    line 12
  2. Distinctive:

    Validate tool-call arguments server-side against the schema: before execution — required keys, types, enums, ranges, AND rejection of …

    line 13
  3. Distinctive:

    Every agent loop has an iteration cap, per-tool timeouts, a token/cost budget, and idempotency keys on tool execution so a retried turn …

    line 31

≈ “Common” is an estimate: at least 1 in 5 of the 350,495 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

LLM App Code

One governing fact: the model is an untrusted, non-deterministic input source that reads like a trusted colleague. Weak LLM-app code trusts the model's JSON, its tool arguments, and its claims about the user; strong code treats every model token as internet input and puts the guarantees in code.

Model output is untrusted input — always

  • Parse defensively. Every parse of model output is wrapped and shape-validated. Expect markdown fences around JSON, leading or trailing prose, truncation at max_tokens, empty strings, and duplicate keys. A malformed response degrades one turn (retry or fallback), never crashes the process.
  • Validate tool-call arguments server-side against the schema before execution — required keys, types, enums, ranges, AND rejection of unexpected keys. The model will eventually send every wrong shape.
  • Map strict-enum values headed to external systems through a server-side table. Model-generated slugs, IDs, plan or network names are never passed through, even when the prompt "guarantees" the format.
  • Authorization never derives from model output. The model proposes; only server-recorded state plus an explicit user action approves. Destructive or financial writes go behind an approval step bound server-side to the specific proposal. Never trust a model's claim about what the user consented to, who the user is, or what a prior turn decided.
  • Prompt injection is transitive. Any tool result containing third-party text (web pages, tickets, emails, file contents) is a channel for instructions to your model. Never give one model turn both (a) exposure to untrusted text and (b) unsupervised dangerous capabilities — split the roles or gate the capability.

Determinism where it matters

Route load-bearing guarantees through code, not prompts: output format, redaction of sensitive fields, which tools the model sees per user or role, output length caps, allowed URL and domain lists. A prompt instruction is a strong suggestion; a deterministic post-processor is a guarantee. Use both (prompt = primary, code = backstop) and write the test against the backstop.

Prompt and model changes are behavior changes

  • Never ship a prompt or model change on vibes. Before editing, capture baseline outputs on a fixed input set — the project's evals, or a smoke set of at least 10 representative inputs including the adversarial ones you can think of. After editing, re-run and diff. Format and safety regressions show up only under repetition.
  • Cache economics: providers cache the prompt prefix. Stable content (system prompt, tool definitions) goes first and byte-identical across turns; variable content (timestamps, user data, retrieved context) goes last. Verify with the cached-token counts in the response usage — a "harmless" reordering can silently multiply cost.
  • Pin model IDs explicitly and verify parameter compatibility when swapping (thinking, effort, temperature defaults and limits differ per model) — read the provider's current docs rather than assuming.

Streaming and the agent loop

  • Handle the full event grammar: partial deltas, tool-use blocks interleaved with text, every stop reason (max_tokens mid-JSON), and error events mid-stream. Test the abort path: a client disconnect mid-generation must cancel upstream and release resources.
  • Every agent loop has an iteration cap, per-tool timeouts, a token/cost budget, and idempotency keys on tool execution so a retried turn can't re-run a side effect.
  • Retry transient API errors with backoff. Never blind-retry a turn whose tool side effects may already have executed.

Cost and latency hygiene

Log tokens and cost per call site from day one. Trim tool results before feeding them back (no 400-row payloads). Choose the model tier per call site deliberately — classification and extraction rarely need the flagship.

Exit check

For each place model output reaches a side effect, trace one path and name the line where each of these happens: parse → schema validation → authorization check → execution → logging. Add fixtures for fenced, truncated, empty, and extra-key outputs to the test suite. If you changed a prompt or model, the report includes the before/after eval results.

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.