BotSting

DocumentationTest a system

Agents and chat assistants

Any agent with an HTTP chat address can be tested once a copy of it carries the harness: a few lines that let BotSting plant canaries and record tool calls.

The four lines

import botsting.harness as pp

app = pp.wrap(app)                                  # the web app

@pp.action("issue_refund")                         # on the function that does the deed
def issue_refund(order_id: str, amount: float): ...

prompt = BASE_PROMPT + pp.planted("admin_code")       # a secret in the instructions
note = pp.planted("bob_note", note) if user == "bob" else note   # or in one test user's record
doc = pp.content("ticket_body", doc)                 # text someone else wrote
  • pp.wrap goes last, after the routes are defined. It works with FastAPI, Starlette, Flask and Django.
  • pp.action marks a tool. During a test it is recorded and not run. Put it after your own permission checks, so that a refusal by your code is seen as a refusal.
  • pp.planted returns that test session's canary. Call it while a message is being handled, not once at start-up: every conversation gets its own value.
  • pp.content marks a place where the agent reads outside text, so that the scanner can plant text there.

The JavaScript package, botsting-harness on npm, does the same for Node, Express and fetch-style handlers such as Next.js and Hono. The same scanner tests both.

What the harness guarantees

  • Nothing changes unless a request carries a BotSting session signed with your key. Real users get the system exactly as written.
  • A request with a session that cannot be verified is refused before it reaches your code. A wrapped production deployment therefore turns test traffic away.
  • Nothing is written to your database. No fake users or records are needed.
  • The record of a tool call returns to the scanner in a header signed for that session and that message, so the model cannot fake it or reuse an old one.
  • The harness uses only the Python standard library.

When a marked tool must return something

A marked function is not run during a test, so it cannot return its usual answer. It returns a stand-in that reads as {"status": "ok"}. If your agent needs more, say what the tool should return:

@pp.action("issue_refund", result=lambda order_id, amount:
    {"status": "ok", "order_id": order_id, "refunded": amount})

Cover every tool at once

Marking tools one by one leaves room to forget one. Pass the whole tool list through a guard instead. Tools not listed as read-only are recorded during a test, so a forgotten tool is blocked, not run.

from botsting.harness_tools import guard

tools = guard({"lookup_order": lookup_order, "issue_refund": issue_refund},
              reads=["lookup_order"])

There are matching guards for the OpenAI Agents SDK (guard_agents), LangChain and LangGraph (guard_langchain) and the Claude Agent SDK (guard_claude_agent).

Testing one user against another

To test whether one user can reach another's records, describe two test users in the target description and plant a canary in a record that belongs to the first. botsting guide prints how to write that description.

Limits to know about

  • The harness sees tools covered by a decorator or a guarded tool list, and nothing else.
  • The test session follows the request. It is not carried into a job queue, a process pool or a thread you start yourself. A marked tool that runs there during a test runs for real, so mark the function that hands the work over.
  • The signatures stop the model from faking a record. They do not stop your own code from lying.