Annotation Interface ToolExample


@Retention(RUNTIME) @Target({}) public @interface ToolExample
Defines an example for a tool/action to help LLMs understand usage patterns.

Tool examples significantly improve LLM accuracy when calling tools, especially for complex parameter handling. Anthropic reports that tool use examples improved accuracy from 72% to 90% on complex parameter handling in their internal testing — see the engineering blog link below for the source.

Usage


 @ActionSpec(
     type = ActionType.LLM,
     description = "Searches academic papers on arXiv",
     examples = {
         @ToolExample(
             description = "Search for recent papers on transformers",
             input = "{\"query\": \"transformer architecture\", \"maxResults\": 5}",
             output = "Found 5 papers: 1. Attention Is All You Need..."
         ),
         @ToolExample(
             description = "Search with date filter",
             input = "{\"query\": \"LLM agents\", \"yearFrom\": 2023}",
             output = "Found 12 papers from 2023 onwards..."
         )
     }
 )
 public ActionResult searchPapers(String query, int maxResults, Integer yearFrom) {
     return result;
 }
 

Best Practices

  • Provide 2-3 examples covering common use cases
  • Include edge cases and complex parameter combinations
  • Use realistic input/output values
  • Add negative examples to show what NOT to do
Since:
0.3.0
Author:
TnsAI Team
See Also:
  • Required Element Summary

    Required Elements
    Modifier and Type
    Required Element
    Description
    Example input as JSON string.
  • Optional Element Summary

    Optional Elements
    Modifier and Type
    Optional Element
    Description
    Brief description of what this example demonstrates.
    boolean
    Whether this is a negative example (showing what NOT to do).
    Expected output or result description.
    Explanation for negative examples - why this is wrong.
  • Element Details

    • description

      String description
      Brief description of what this example demonstrates. Should clearly state the use case or scenario.
      Returns:
      example description
      Default:
      ""
    • input

      String input
      Example input as JSON string. Should match the tool's parameter schema.

      Example: "{\"query\": \"machine learning\", \"limit\": 10}"

      Returns:
      JSON input string
    • output

      String output
      Expected output or result description. Can be actual output or a description of what to expect.
      Returns:
      output string
      Default:
      ""
    • negative

      boolean negative
      Whether this is a negative example (showing what NOT to do). Negative examples help LLMs avoid common mistakes.
      Returns:
      true if this is a negative/bad example
      Default:
      false
    • whyBad

      String whyBad
      Explanation for negative examples - why this is wrong. Only applicable when negative = true.
      Returns:
      explanation of why this example is wrong
      Default:
      ""