Use Tool.Create to describe a method’s arguments and return value. No model call or API key.
dotnet add package RecursiveAI.OneLlmRequires .NET 10 (net10.0); .NET 9 and earlier aren’t supported.
using OneLlm.Tools; var spec = Tool.Create("in_stock", (string sku, CancellationToken ct) => sku == "A1").Definition; Console.WriteLine(spec.InputSchema); Console.WriteLine(spec.OutputSchema);
Unzip the example, then dotnet run.
Prints the input schema for sku, then the Boolean output schema. The cancellation parameter isn’t a JSON property:
{ "type": "object", "properties": { "sku": { "type": "string" } }, "required": [ "sku" ], "additionalProperties": false } { "type": "boolean" }
The full program
The download builds a tool from the Catalog.Reserve method. The method’s signature and attributes are the only inputs. Generating the schemas doesn’t invoke the method.
using System.ComponentModel; using System.ComponentModel.DataAnnotations; using System.Text.Json; using OneLlm.Tools; var tool = Tool.Create(Catalog.Reserve).Definition; var pretty = new JsonSerializerOptions { WriteIndented = true }; Console.WriteLine($"{tool.Name}: {tool.Description}"); Console.WriteLine("Input:"); Console.WriteLine(tool.InputSchema.ToJsonString(pretty)); Console.WriteLine("Output:"); Console.WriteLine(tool.OutputSchema?.ToJsonString(pretty)); record Reservation(string Sku, int Quantity); static class Catalog { [Description("Describe a stock reservation.")] public static Reservation Reserve( [Description("Stock code")] string sku, CancellationToken cancellationToken, [Range(1, 20)] int quantity = 1) { cancellationToken.ThrowIfCancellationRequested(); return new Reservation(sku, quantity); } }
dotnet run prints:
reserve: Describe a stock reservation. Input: { "type": "object", "properties": { "sku": { "type": "string", "description": "Stock code" }, "quantity": { "type": "integer", "minimum": 1, "maximum": 20, "default": 1 } }, "required": [ "sku" ], "additionalProperties": false } Output: { "type": "object", "properties": { "sku": { "type": "string" }, "quantity": { "type": "integer", "minimum": -2147483648, "maximum": 2147483647 } }, "required": [ "sku", "quantity" ], "additionalProperties": false }
sku is required, while quantity is optional with a default of 1 and a range of 1 to 20. The record returned by Reserve has its own schema. If the signature uses an unsupported type such as a multidimensional array, Tool.Create throws NotSupportedException.
Variations
Write the schema to a file. After creating spec in the snippet at the top:
File.WriteAllText("tool-input.json", spec.InputSchema.ToString());
Related recipes
The short answer
Pass a delegate to Tool.Create and inspect its Definition.InputSchema and Definition.OutputSchema. This is local reflection over a C# signature, not a prompt asking a model to write JSON. The input schema is a closed JSON object: it names the arguments the caller can supply, their types, and which are required. The output schema describes a supported typed return, such as a Boolean or record. The two schemas answer different questions; OneLLM sends the input schema to the model, not the return schema shown here.
How do C# parameters become a tool’s JSON Schema?
OneLLM uses the parameter’s C# name as the JSON property name. A default makes the argument optional. A nullable parameter without a default is still required: the caller must send its property, but the value can be JSON null. CancellationToken and ToolContext are different: the runtime supplies them when it invokes the tool, so they don’t belong in the JSON at all. The full example declares cancellationToken but shows only sku and quantity under properties.
Can you add descriptions and validation rules to generated JSON Schema?
For this reflection path, add [Description] to a method or parameter. The method attribute fills the tool’s description; the parameter attribute becomes a description inside the input schema. [Range] on a numeric parameter replaces the normal bounds for the C# type. Here the input quantity is constrained to 1 through 20, while the output record’s quantity is a separate property with the usual int bounds. The annotation doesn’t follow the value from input to output. To constrain the output property, annotate it on the record itself. The tool schema reference lists other supported annotations and explains how provider clients adapt schemas to the keywords their APIs support.
Is a tool schema the same as a JSON Schema for a C# class?
No. A type schema, such as the one produced by the .NET JSON schema exporter, describes a serialization contract for a type. A tool’s input schema describes a method call: which arguments have defaults, what to name them, and which parameters the runtime injects instead of accepting from JSON. The return can be a type schema but isn’t always one. A string return is a text result and has no OutputSchema; Task<T> and ValueTask<T> are unwrapped to inspect T.