Chapter 7: Guardrails

Put guardrails in code, not in the prompt.

  • Argument checks. Reject a minutes value outside 1 to 1440 before the tool runs. Return the error text to the model.
  • Allowlist. Each agent has a fixed set of tool names. Reject any other name.
  • Loop detection. Count each tool name plus arguments. Stop when one key repeats three times.
Figure 7.1. The three guardrails, in front of every tool. Each one is a line of Java, so the model cannot talk its way past it.
docs