Skip to content
Back to skills

Llm Call Site Contract

ASecurity

Use when you write or review code, a workflow script or a hook in which a model's reply is parsed and then decides a branch, becomes a command, a path or a query, or is written to state, above all when no person reads it first. The guarantee the program relies on has to come from the code around the call, because a constraint that is only requested in the prompt is not enforced. Trace where the reply flows, write the expected contract (pre-conditions, prompt constraints, post-conditions) befo...

  • 72 stars
  • 0 votes
  • 0 copies
  • 1 view
  • Added November 30, 2026
ai-agentsrustgoexpress

Works with

  • cli

Security analysis

A100/100

Pro scans all 2 files and shows the line behind each finding

Scanned November 30, 2026

npx -y skills add Tibsfox/gsd-skill-creator --skill llm-call-site-contract --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Llm Call Site Contract?

Add the live security badge to your README. It updates with every re-scan.

Security grade badge for Llm Call Site Contract
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/tibsfox-llm-call-site-contract/badge)](https://www.skillsdirectory.com/skills/tibsfox-llm-call-site-contract)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

Download with Pro
SKILL.md
---
name: llm-call-site-contract
description: >
  Use when you write or review code, a workflow script or a hook in which a
  model's reply is parsed and then decides a branch, becomes a command, a path
  or a query, or is written to state, above all when no person reads it first.
  The guarantee the program relies on has to come from the code around the
  call, because a constraint that is only requested in the prompt is not
  enforced. Trace where the reply flows, write the expected contract
  (pre-conditions, prompt constraints, post-conditions) before reading the
  existing checks, pair every prompt constraint with a code check, make the
  failure path closed, and test the site with malformed replies. Distinct from
  tool-result-status-declaration (your own reading of a tool result) and
  test-oracle-independence (where expected values come from). Backed by an
  empirical study of call-site contracts (arxiv 2610.24545). Triggers on
  wiring a model call into control flow and on reviewing an agent pipeline.
description-frequency: on-demand
user-invocable: true
version: 1.0.0
format: 2025-10-02
triggers:
  - "parse the model's JSON reply and route on its verdict field"
  - "review this pipeline step where an LLM picks the next command"
  - "add a classifier call that decides whether the action is allowed"
updated: 2026-11-28
status: ACTIVE
source: arxiv 2610.24545 (call-site contracts in agentic systems)
---

# LLM Call-Site Contract

A review of one place in the code: where a model is called and its reply
re-enters the program. The program around that place must supply the guarantee
the model cannot.

## Why

Agentic systems replace parts of their logic, such as choosing the next tool,
judging whether an action is allowed or writing code to run, with calls to a
language model. The program still relies on what this logic must guarantee,
but the model's behaviour is not fixed by code, varies across runs and can be
steered by its input, so the guarantee must come from the program around each
call site, as a contract of pre-conditions, prompt constraints and
post-conditions. An empirical study of 496 LLM call sites in 40 popular
open-source agentic systems (arxiv 2610.24545) traces where every model output
flows, derives an expected contract for each call site without access to its
code, and compares it with the contract the code implements. 48% of LLM
outputs reach control flow or execution, and 73% of these never reach a
person. Programs enforce 78% of their constraints in code, but in the prompt
67% of the constraints are only requested from the model. Although 82% of call
sites are checked before and after the call, 63% of the expected constraints
are unmet and only 5.3% of call sites satisfy their whole contract; ten
recurring patterns explain 99% of the gaps. 38 mechanisms behind these gaps
trigger at runtime, and a small code fix that enforces the expected constraint
stops all 38. The presence of checks says little about their adequacy.

This repository has such sites: the critique reviewer
(`src/critique/subagent-client.ts`), the conflict rewrite suggester
(`src/conflicts/rewrite-suggester.ts`), the arXiv ranker
(`src/scan-arxiv/ranker.ts`), the activation analyzer
(`src/activation/llm-activation-analyzer.ts`), and workflow scripts that
branch on an agent's reply. The critique site shows the pattern at small scale
(read at v1.49.1132). Both reviewer prompts request the reply as a JSON object
with a `findings` list. The code parses the reply and turns malformed JSON
into an error finding, which is a post-condition enforced in code. A reply
that is well-formed JSON with no `findings` key is read as an empty list, and
`loop.ts` counts a stage with zero findings as passed. The shape of the reply
is requested in the prompt and is not checked in code.

## Data classes touched

Reads source code and prompts (project-internal). Boundary rules: (1) test
replies are synthetic, and a test never sends real credentials or
`never-surface` content to a model; (2) the contract is recorded beside the
call site, as a comment or as tests, and not in a prompt alone.

## How

1. **Find the call site and trace the reply.** For each place a model is
   called, follow the returned text to where it is used and name the sink:

   | Sink | Examples | Weight |
   |---|---|---|
   | shown to a person | a summary, a suggestion awaiting approval | lowest |
   | control flow | a branch, a loop bound, a route, a pass or fail verdict | high |
   | execution | a command, code, a query, a file path, a tool argument | highest |
   | stored state | memory, a config, a file later read as fact | high |

2. **Write the expected contract before reading the checks.** From what the
   program does with the reply, write what must hold: *pre-conditions* (what
   goes in: size, required fields, untrusted content fenced as data); *prompt
   constraints* (what the prompt asks for: format, allowed values,
   prohibitions); *post-conditions* (what the reply must satisfy before the
   sink: it parses, it has the required keys, its values are inside the
   allowed set, what it references exists). Writing it first keeps the
   existing checks from defining the contract.
3. **Pair each constraint with code.** For every prompt constraint and
   post-condition, find the line of code that rejects a reply which violates
   it. Mark each one *enforced* (code rejects the violation), *requested* (the
   prompt asks, nothing checks) or *absent*. A check that exists and still
   passes a violating reply (a cast, a default that fills a missing field, a
   parse that accepts any object) counts as requested.
4. **Close the failure path.** For each requested or absent constraint whose
   sink is control flow, execution or stored state, add the check: validate
   against a schema, test membership in the allowed set, bound sizes, resolve
   and confine paths, check that referenced ids exist. On a violation the code
   takes the closed branch (reject, a bounded retry, or an error a person
   sees), never a permissive default such as an empty list that reads as
   "nothing found" or a missing verdict that reads as "allowed".
5. **Guard the input side.** Content from outside the program that enters the
   prompt is fenced as data and cannot widen what the reply is allowed to do:
   the post-conditions hold whatever the input says
   (`taint-capability-narrowing`).
6. **Test the site with bad replies.** Add tests that feed the code after the
   call an empty reply, prose in place of the format, a well-formed reply with
   a missing key, a value outside the allowed set, and an oversized reply.
   Each must reach the closed branch. Add one more: a well-formed reply whose
   free-text field carries an instruction. That text must not reach any sink
   other than display or a log, and the other post-conditions must still hold.
   Take the expected outcomes from the contract of step 2, not from what the
   code currently does (`test-oracle-independence`).
7. **Record the contract at the site.** A short comment, or the names of the
   tests, state the three parts, so that a later edit to the prompt shows up
   as a contract change.

### Robustness rule

Judge a call site by what a violating reply does to the program, not by
whether a parse and a try/catch are present. Checks before and after the call
were present at 82% of the studied sites; the whole contract held at 5.3%.

## Confidence / failure model

Deriving the expected contract is an **LLM judgment** (the paper's own
derivation used a multi-agent pipeline validated by human judgments), and it
can miss an obligation or invent one. The figures are the paper's, for 40
open-source systems in four languages; they are not a measurement of this
repository or of this skill. The sink table, the three marks, the
closed-branch rule of step 4, the list of bad replies and step 7 are this
skill's design, and the paper's ten gap patterns are not reproduced here. The
description of the critique site was read from the source at v1.49.1132 and
goes stale when that code changes. Fail-closed defaults: (a) a constraint for
which you cannot find a rejecting line is requested, not enforced; (b) a reply
that fails a post-condition never reaches execution or stored state; (c) at a
site you were not asked to change, a missing check is reported with the
violating reply as evidence, and the change is proposed.

## When to skip

- The reply is only shown to a person who decides what to do with it, and
  nothing parses it.
- The call goes through an interface that already enforces a schema at the
  tool-call layer and the code uses only the validated fields: check the
  conditions a schema does not express (ranges, membership, existence), then
  stop.
- A script run once by hand and not kept.

## Integration

- **tool-result-status-declaration** — the agent's own habit when it builds on
  a tool result; this skill is the same idea written into code that calls a
  model.
- **test-oracle-independence** — expected outcomes for the bad-reply tests
  come from the contract.
- **taint-capability-narrowing** — untrusted content in the prompt; the
  post-conditions are what keeps it from steering the sink.
- **guard-form-invariance-test** — when the call site is itself a guard, test
  its decisions across surface forms as well.
- **weakest-runner-skill-check** — a requested constraint was tried, if at
  all, on the model that was in use when the code was written; enforce it
  before another tier runs the site.
- **relay-sufficiency-gate** — a subagent report consumed by a script is a
  call-site reply: give it a schema.

Files in this skill

  • SKILL.md9.4 KB
  • triggering.test.md2.4 KB

Attribution

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

View all in ai-agents →

Comments

Loading comments…

Newsletter

Get the weekly list of safe new skills, and the ones we pulled.