Skip to content

BugFix Issue #3731 json schema input schema #3845

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: development
Choose a base branch
from

Conversation

RogerBarreto
Copy link

@RogerBarreto RogerBarreto commented May 28, 2025

This pull request introduces changes to improve the handling of Document objects and schema generation in the BedrockChatClient class within the AWSSDK.Extensions.Bedrock.MEAI extension. The updates streamline the creation of input schemas and ensure consistency in Document initialization.

Fix to Document default:

This change prevents an error while advertising the function result back to the API, as it says the toolInput cannot be null, by setting the default as empty dictionary sorts the error.

Enhancements to schema generation:

  • handling type, properties, and required fields in a more structured manner, this avoid advertising those properties when they are not present. Any execution of a function that has no arguments were failing before this fix.

Reproduction Bug

using Amazon.BedrockRuntime;
using Microsoft.Extensions.AI;
using Microsoft.Extensions.DependencyInjection;
using System.Globalization;

var services = new ServiceCollection();
services.TryAddAWSService<IAmazonBedrockRuntime>();

var runtime = services.BuildServiceProvider().GetRequiredService<IAmazonBedrockRuntime>();

var chatClient = runtime.AsIChatClient().AsBuilder().UseFunctionInvocation().Build();

var aiFunction = AIFunctionFactory.Create(() => DateTime.UtcNow.ToString("d", CultureInfo.InvariantCulture), "GetCurrentDate", "Returns the current date in UTC format.");

var chatOptions = new ChatOptions
{
    ModelId = "anthropic.claude-3-5-sonnet-20240620-v1:0",
    Tools = [aiFunction],
};

var response = await chatClient.GetResponseAsync([
    new ChatMessage(ChatRole.User, "What is the current date?"),
], chatOptions);

Console.WriteLine($"Response: {response}");

@RogerBarreto RogerBarreto changed the base branch from main to development May 28, 2025 18:49
@RogerBarreto RogerBarreto changed the title Issues/3731 json schema input schema BugFix Issue #3731 json schema input schema May 28, 2025
@boblodgett boblodgett self-requested a review May 29, 2025 16:11
@boblodgett boblodgett requested a review from dscpinheiro May 29, 2025 16:18
@boblodgett boblodgett added bug This issue is a bug. v4 labels May 29, 2025
@RogerBarreto
Copy link
Author

I miss a place to add integration tests in this repo, if we can hook up any with the support of the team would be very helpful to ensure the functionality. Currently I had to create a test on my local side and only this way was capable of replicating the problem and solving it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug This issue is a bug. v4
Projects
None yet
Development

Successfully merging this pull request may close these issues.

The json schema definition at toolConfig.tools.10.toolSpec.inputSchema is invalid
3 participants