Portal Community

ToolDefinition Structure

public class ToolDefinition
{
    public string       Name        { get; init; } = string.Empty;
    public string       Description { get; init; } = string.Empty;
    public JsonDocument InputSchema { get; init; } = JsonDocument.Parse("{}");
}

// Example: well-written tool definition
var leaveTool = new ToolDefinition
{
    Name        = "get_employee_leave_balance",
    Description = "Returns the number of annual leave days remaining for an employee. " +
                  "Call this when the user asks about their leave balance, remaining days, " +
                  "or how many days they can take off.",
    InputSchema = JsonDocument.Parse("""
    {
      "type": "object",
      "properties": {
        "employeeId": {
          "type":        "string",
          "description": "The employee's unique ID (e.g. 'EMP-1042'). " +
                         "Obtain from the user if not already known."
        },
        "year": {
          "type":        "integer",
          "description": "The leave year (defaults to current year if not specified)."
        }
      },
      "required": ["employeeId"]
    }
    """)
};

JSON Schema Types

JSON Schema TypeC# EquivalentLLM Behaviour
"type": "string"stringLLM passes a quoted string value
"type": "integer"intLLM passes a numeric integer
"type": "number"doubleLLM passes a numeric value (may have decimals)
"type": "boolean"boolLLM passes true or false
"type": "array"List<T>LLM passes a JSON array
"type": "object"classLLM passes a nested JSON object
"enum": [...]enumLLM picks from the specified values

Writing Effective Descriptions

The tool description is the most important field for reliable tool selection. Guidelines:

Schema Anti-Patterns

Anti-PatternProblemFix
Vague description: "Gets leave data"LLM doesn't know when to call it"Returns remaining annual leave days. Call when user asks about leave balance."
All parameters requiredLLM fails if it can't determine a valueMake optional parameters optional; provide defaults in the handler
Overlapping tool namesLLM picks the wrong oneEnsure each tool has a distinct, unambiguous purpose
No parameter descriptionsLLM guesses parameter formatDescribe expected format for each parameter

Generating Schemas from C# Types

// Use a schema generator to avoid hand-writing JSON Schema
public class LeaveBalanceInput
{
    [JsonPropertyName("employeeId")]
    [Description("The employee's unique ID, e.g. 'EMP-1042'")]
    public string EmployeeId { get; set; } = string.Empty;

    [JsonPropertyName("year")]
    [Description("Leave year; defaults to current year if omitted")]
    public int? Year { get; set; }
}

// Generate schema using NJsonSchema or System.Text.Json.Schema
JsonSchema schema = JsonSchema.FromType<LeaveBalanceInput>();
string jsonSchemaString = schema.ToJson();