Skip to main content

Tool Polish

defineTool() exposes three additional fields in v2.0 that materially improve reliability and cost.

1. strict: true — guaranteed valid arguments

When strict: true:
  • additionalProperties: false is appended to the generated JSON Schema, so the LLM cannot send junk extra keys.
  • For OpenAI-family models, strict: true flows through to the API’s structured-output mode, which guarantees the model’s tool call is valid JSON matching your schema (no retries, no parse errors).
When to use: any tool whose schema you want to enforce hard — DB queries, payment operations, anything where “the LLM made up a field” would be embarrassing. Trade-offs:
  • OpenAI strict mode disables certain features (anyOf, default values on optional fields). If your schema fails to compile in strict mode, drop the flag.
  • Anthropic / Google providers ignore the strict flag at the API level but the JSON Schema is still tightened, which the model usually respects.

2. inputExamples — N-shot demonstrations

The framework appends a formatted examples section to the tool description that the LLM sees:
Why this works: LLMs are extraordinarily good at pattern-matching from examples. A single well-chosen example often beats two paragraphs of prose explanation. When to use:
  • Tools with enums or specific value formats (timezones, country codes, ISO dates)
  • Tools where the LLM tends to over- or under-specify (e.g. always omits an optional field that improves results)
  • New tools you don’t have months of usage data on yet
Tips:
  • 3–5 examples is the sweet spot. More doesn’t help and increases prompt cost.
  • Show variety, not similarity. The model already understands that strings can vary; show it the kinds of variation that matter.
  • Don’t include obvious “bad” examples — the model can latch onto them.

3. toModelOutput — async result transformer

Execution order:
toModelOutput runs BEFORE the artifact auto-converter, so if your transform shrinks the output below the threshold, no pointer is created. Signature:
ctx gives you access to userId, tenantId, sessionState, eventBus — useful for tenant-aware transforms (redact PII per tenant policy, etc.). When to use:
  • Compress / summarize / redact tool output without modifying the underlying tool
  • Convert verbose API responses to LLM-friendly shapes
  • Strip secrets that shouldn’t reach the model (API keys, internal IDs)
  • A/B test response formats without touching execute
toModelOutput vs Memory Pointers:

Putting it together

All three flags compose cleanly: strict ensures valid input, examples teach the model what valid input looks like, toModelOutput keeps the response footprint small.

See also