Skip to content

.NET [Feature]: Consider including return type schema in generated tool definitions #5153

@jaliyaudagedara

Description

@jaliyaudagedara

Description

Currently the generated tool schema only includes input parameters. When a tool returns a typed object (e.g., a record), the LLM has no way to know the return shape unless the developer manually describes it in the method's [Description]. This is redundant when the type already exists and can drift out of sync.

record WeatherResult(int Temperature, string Description);

[Description("Returns weather data for a given city.")]
static WeatherResult GetWeather(
    [Description("The city to get the weather for.")] string city)
{
    return new WeatherResult(18, "Rainy");
}

Inspecting the generated tool:

var weatherTool = AIFunctionFactory.Create(GetWeather);
Console.WriteLine($"Description: {weatherTool.Description}");
Console.WriteLine($"JsonSchema: {weatherTool.JsonSchema}");

Generated Description and schema today:

Description:

Returns weather data for a given city.

JsonSchema:

{
    "type": "object",
    "properties": {
        "city": {
            "description": "The city to get the weather for.",
            "type": "string"
        }
    },
    "required": [
        "city"
    ]
}

No mention of WeatherResult, Temperature, or Description.

Code Sample

Ability to be fully explicit:

record WeatherResult(
    [property: Description("Temperature in Celsius.")] int Temperature,
    [property: Description("Weather description.")] string Description);

[Description("Returns weather data for a given city.")]
static WeatherResult GetWeather(
    [Description("The city to get the weather for.")] string city)
{
    return new WeatherResult(18, "Rainy");
}

Would generate,

{
    "type": "object",
    "properties": {
        "city": {
            "description": "The city to get the weather for.",
            "type": "string"
        }
    },
    "required": [
        "city"
    ],
    "returns": {
        "type": "object",
        "properties": {
            "temperature": {
                "description": "Temperature in Celsius.",
                "type": "integer"
            },
            "description": {
                "description": "Weather description.",
                "type": "string"
            }
        }
    }
}

Or simply by property names,

record WeatherResult(int Temperature, string Description);

[Description("Returns weather data for a given city.")]
static WeatherResult GetWeather(
    [Description("The city to get the weather for.")] string city)
{
    return new WeatherResult(18, "Rainy");
}

Would generate,

{
    "type": "object",
    "properties": {
        "city": {
            "description": "The city to get the weather for.",
            "type": "string"
        }
    },
    "required": [
        "city"
    ],
    "returns": {
        "type": "object",
        "properties": {
            "temperature": {
                "type": "integer"
            },
            "description": {
                "type": "string"
            }
        }
    }
}

Language/SDK

.NET

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions