CSharpToJsonSchema 3.10.2-dev.22
CSharpToJsonSchema
Features 🔥
- Source generator to define functions natively through C# interfaces and individual methods
- Doesn't use Reflection
- All modern .NET features - nullability, trimming, NativeAOT, etc.
- Tested for compatibility with OpenAI/Ollama/Anthropic/LangChain/Gemini
Usage
Interface
using CSharpToJsonSchema;
public enum Unit
{
Celsius,
Fahrenheit,
}
public class Weather
{
public string Location { get; set; } = string.Empty;
public double Temperature { get; set; }
public Unit Unit { get; set; }
public string Description { get; set; } = string.Empty;
}
[GenerateJsonSchema(Strict = true)] // false by default. You can't use parameters with default values in Strict mode.
public interface IWeatherFunctions
{
[Description("Get the current weather in a given location")]
public Task<Weather> GetCurrentWeatherAsync(
[Description("The city and state, e.g. San Francisco, CA")] string location,
Unit unit,
CancellationToken cancellationToken = default);
}
public class WeatherService : IWeatherFunctions
{
public Task<Weather> GetCurrentWeatherAsync(string location, Unit unit = Unit.Celsius, CancellationToken cancellationToken = default)
{
return Task.FromResult(new Weather
{
Location = location,
Temperature = 22.0,
Unit = unit,
Description = "Sunny",
});
}
}
var tools = service.AsTools();
Methods
[FunctionTool]
public Task<Weather> GetCurrentWeatherAsync(string location, Unit unit = Unit.Celsius, CancellationToken cancellationToken = default)
{
return Task.FromResult(new Weather
{
Location = location,
Temperature = 22.0,
Unit = unit,
Description = "Sunny",
});
}
var tools = new Tools([GetCurrentWeatherAsync])
//Access list of CSharpToJsonSchema.Tool
var myTools = tools.AvailableTools
//Implicit Conversion to list of CSharpToJsonSchema.Tool
List<Tool> myTools = tools
Support
Priority place for bugs: https://github.com/tryAGI/CSharpToJsonSchema/issues
Priority place for ideas and general questions: https://github.com/tryAGI/CSharpToJsonSchema/discussions
Discord: https://discord.gg/Ca2xhfBf3v
Acknowledgments

This project is supported by JetBrains through the Open Source Support Program.
This project is supported by CodeRabbit through the Open Source Support Program.
.NET Framework 4.6.2
- Microsoft.Extensions.AI.Abstractions (>= 9.3.0-preview.1.25114.11)
- System.Text.Json (>= 9.0.0)
.NET 8.0
- Microsoft.Extensions.AI.Abstractions (>= 9.3.0-preview.1.25114.11)
- System.Text.Json (>= 9.0.0)
.NET 9.0
- Microsoft.Extensions.AI.Abstractions (>= 9.3.0-preview.1.25114.11)
- System.Text.Json (>= 9.0.0)
.NET Standard 2.0
- Microsoft.Extensions.AI.Abstractions (>= 9.3.0-preview.1.25114.11)
- System.Text.Json (>= 9.0.0)
| Version | Downloads | Last updated |
|---|---|---|
| 3.10.2-dev.106 | 3 | 03/21/2026 |
| 3.10.2-dev.105 | 3 | 03/21/2026 |
| 3.10.2-dev.104 | 3 | 03/21/2026 |
| 3.10.2-dev.103 | 4 | 03/21/2026 |
| 3.10.2-dev.102 | 3 | 03/21/2026 |
| 3.10.2-dev.101 | 3 | 03/21/2026 |
| 3.10.2-dev.100 | 3 | 03/21/2026 |
| 3.10.2-dev.99 | 2 | 03/21/2026 |
| 3.10.2-dev.97 | 2 | 03/21/2026 |
| 3.10.2-dev.96 | 2 | 03/21/2026 |
| 3.10.2-dev.90 | 2 | 03/19/2026 |
| 3.10.2-dev.89 | 2 | 03/19/2026 |
| 3.10.2-dev.88 | 3 | 03/19/2026 |
| 3.10.2-dev.85 | 2 | 03/17/2026 |
| 3.10.2-dev.84 | 2 | 03/17/2026 |
| 3.10.2-dev.83 | 2 | 03/17/2026 |
| 3.10.2-dev.82 | 2 | 03/17/2026 |
| 3.10.2-dev.80 | 2 | 03/17/2026 |
| 3.10.2-dev.69 | 2 | 03/06/2026 |
| 3.10.2-dev.39 | 3 | 03/06/2026 |
| 3.10.2-dev.34 | 2 | 03/06/2026 |
| 3.10.2-dev.32 | 2 | 03/06/2026 |
| 3.10.2-dev.31 | 3 | 03/06/2026 |
| 3.10.2-dev.29 | 3 | 03/06/2026 |
| 3.10.2-dev.28 | 2 | 03/06/2026 |
| 3.10.2-dev.26 | 2 | 03/06/2026 |
| 3.10.2-dev.25 | 3 | 03/06/2026 |
| 3.10.2-dev.22 | 2 | 03/06/2026 |
| 3.10.2-dev.21 | 3 | 03/06/2026 |
| 3.10.2-dev.18 | 3 | 03/06/2026 |
| 3.10.2-dev.16 | 3 | 03/06/2026 |
| 3.10.1 | 4 | 03/06/2026 |
| 3.9.2-dev.3 | 3 | 03/06/2026 |
| 3.9.2-dev.2 | 3 | 03/06/2026 |
| 3.9.1 | 4 | 03/06/2026 |
| 3.9.0 | 4 | 03/06/2026 |
| 3.8.2-dev.13 | 2 | 03/06/2026 |
| 3.8.2-dev.10 | 2 | 03/06/2026 |
| 3.8.2-dev.9 | 2 | 03/06/2026 |
| 0.0.0-dev.1 | 3 | 03/06/2026 |