Skip to content
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

The json schema definition at toolConfig.tools.10.toolSpec.inputSchema is invalid #3731

Open
1 task
cristiursachi opened this issue Mar 28, 2025 · 3 comments
Open
1 task
Labels
bug This issue is a bug. Extensions p2 This is a standard priority issue queued

Comments

@cristiursachi
Copy link

cristiursachi commented Mar 28, 2025

Describe the bug

I'm trying to use the new AWSSDK.Extensions.Bedrock.MEAI extensions but I get a server side error:

The json schema definition at toolConfig.tools.10.toolSpec.inputSchema is invalid. Fix the following errors and try again: $.properties: null found, object expected

This is thrown when I use an AITool in ChatOptions as following:

IChatClient client = runtime.AsChatClient("us.anthropic.claude-3-7-sonnet-20250219-v1:0");

 ChatOptions chatOptions = new ChatOptions();
 
  AITool toolInLine = MyTools.GetAITestTool();

  chatOptions.Tools.Add(toolInLine);

 client.GetStreamingResponseAsync(messages,chatOptions);

Regression Issue

  • Select this option if this issue appears to be a regression.

Expected Behavior

I should get a valid response from Bedrock LLM and invoke the AITool if required. But despite if the prompt will require or not the call to AITool, I get the the exception which seems generated on serverSide.

Current Behavior

This is the full exception I get:

Amazon.BedrockRuntime.Model.ValidationException
  HResult=0x80131500
  Message=The json schema definition at toolConfig.tools.10.toolSpec.inputSchema is invalid. Fix the following errors and try again: $.properties: null found, object expected
  Source=AWSSDK.Core
  StackTrace:
   at Amazon.Runtime.Internal.HttpErrorResponseExceptionHandler.HandleExceptionStream(IRequestContext requestContext, IWebResponseData httpErrorResponse, HttpErrorResponseException exception, Stream responseStream) in C: \source\repos\aws-sdk-net-4\sdk\src\Core\Amazon.Runtime\Pipeline\ErrorHandler\HttpErrorResponseExceptionHandler.cs:line 163
   at Amazon.Runtime.Internal.HttpErrorResponseExceptionHandler.<HandleExceptionAsync>d__2.MoveNext() in C: \source\repos\aws-sdk-net-4\sdk\src\Core\Amazon.Runtime\Pipeline\ErrorHandler\HttpErrorResponseExceptionHandler.cs:line 92
   at Amazon.Runtime.Internal.ExceptionHandler`1.<HandleAsync>d__6.MoveNext() in C: \source\repos\aws-sdk-net-4\sdk\src\Core\Amazon.Runtime\Pipeline\ErrorHandler\ExceptionHandler.cs:line 46
   at Amazon.Runtime.Internal.ErrorHandler.<ProcessExceptionAsync>d__8.MoveNext() in C: \source\repos\aws-sdk-net-4\sdk\src\Core\Amazon.Runtime\Pipeline\ErrorHandler\ErrorHandler.cs:line 205
   at Amazon.Runtime.Internal.ErrorHandler.<InvokeAsync>d__5`1.MoveNext() in C: \source\repos\aws-sdk-net-4\sdk\src\Core\Amazon.Runtime\Pipeline\ErrorHandler\ErrorHandler.cs:line 103
   at Amazon.Runtime.Internal.CallbackHandler.<InvokeAsync>d__9`1.MoveNext() in C: \source\repos\aws-sdk-net-4\sdk\src\Core\Amazon.Runtime\Pipeline\Handlers\CallbackHandler.cs:line 61
   at Amazon.Runtime.Internal.Signer.<InvokeAsync>d__1`1.MoveNext() in C: \source\repos\aws-sdk-net-4\sdk\src\Core\Amazon.Runtime\Pipeline\Handlers\Signer.cs:line 59
   at Amazon.Runtime.Internal.EndpointDiscoveryHandler.<InvokeAsync>d__2`1.MoveNext() in C: \source\repos\aws-sdk-net-4\sdk\src\Core\Amazon.Runtime\Pipeline\Handlers\EndpointDiscoveryHandler.cs:line 80
   at Amazon.Runtime.Internal.EndpointDiscoveryHandler.<InvokeAsync>d__2`1.MoveNext() in C: \source\repos\aws-sdk-net-4\sdk\src\Core\Amazon.Runtime\Pipeline\Handlers\EndpointDiscoveryHandler.cs:line 90
   at Amazon.Runtime.Internal.RetryHandler.<InvokeAsync>d__10`1.MoveNext() in C: \source\repos\aws-sdk-net-4\sdk\src\Core\Amazon.Runtime\Pipeline\RetryHandler\RetryHandler.cs:line 135
   at Amazon.Runtime.Internal.RetryHandler.<InvokeAsync>d__10`1.MoveNext() in C: \source\repos\aws-sdk-net-4\sdk\src\Core\Amazon.Runtime\Pipeline\RetryHandler\RetryHandler.cs:line 150
   at Amazon.Runtime.Internal.CallbackHandler.<InvokeAsync>d__9`1.MoveNext() in C: \source\repos\aws-sdk-net-4\sdk\src\Core\Amazon.Runtime\Pipeline\Handlers\CallbackHandler.cs:line 61
   at Amazon.Runtime.Internal.BaseAuthResolverHandler.<InvokeAsync>d__2`1.MoveNext() in C: \source\repos\aws-sdk-net-4\sdk\src\Core\Amazon.Runtime\Pipeline\Handlers\BaseAuthResolverHandler.cs:line 47
   at Amazon.Runtime.Internal.CallbackHandler.<InvokeAsync>d__9`1.MoveNext() in C: \source\repos\aws-sdk-net-4\sdk\src\Core\Amazon.Runtime\Pipeline\Handlers\CallbackHandler.cs:line 61
   at Amazon.Runtime.Internal.ErrorCallbackHandler.<InvokeAsync>d__5`1.MoveNext() in C: \source\repos\aws-sdk-net-4\sdk\src\Core\Amazon.Runtime\Pipeline\Handlers\ErrorCallbackHandler.cs:line 53
   at Amazon.Runtime.Internal.MetricsHandler.<InvokeAsync>d__1`1.MoveNext() in C: \source\repos\aws-sdk-net-4\sdk\src\Core\Amazon.Runtime\Pipeline\Handlers\MetricsHandler.cs:line 93
   at Amazon.BedrockRuntime.BedrockChatClient.<GetStreamingResponseAsync>d__7.MoveNext() in C: \source\repos\aws-sdk-net-4\extensions\src\AWSSDK.Extensions.Bedrock.MEAI\BedrockChatClient.cs:line 158
   at Amazon.BedrockRuntime.BedrockChatClient.<GetStreamingResponseAsync>d__7.System.Threading.Tasks.Sources.IValueTaskSource<System.Boolean>.GetResult(Int16 token)
   at ASI_AutoRemedy.Program.<Main>d__0.MoveNext() in C: \source\repos\ASI_AutoRemedy\ASI_AutoRemedy\Program.cs:line 79
   at ASI_AutoRemedy.Program.<Main>d__0.MoveNext() in C: \source\repos\ASI_AutoRemedy\ASI_AutoRemedy\Program.cs:line 79

  This exception was originally thrown at this call stack:
    Amazon.Runtime.HttpWebRequestMessage.ProcessHttpResponseMessage(System.Net.Http.HttpResponseMessage) in HttpRequestMessageFactory.cs
    Amazon.Runtime.HttpWebRequestMessage.GetResponseAsync(System.Threading.CancellationToken) in HttpRequestMessageFactory.cs
    Amazon.Runtime.Internal.HttpHandler<TRequestContent>.InvokeAsync<T>(Amazon.Runtime.IExecutionContext) in HttpHandler.cs
    Amazon.Runtime.Internal.Unmarshaller.InvokeAsync<T>(Amazon.Runtime.IExecutionContext) in Unmarshaller.cs
    Amazon.Runtime.Internal.ErrorHandler.InvokeAsync<T>(Amazon.Runtime.IExecutionContext) in ErrorHandler.cs

Inner Exception 1:
HttpErrorResponseException: Exception of type 'Amazon.Runtime.Internal.HttpErrorResponseException' was thrown.

Reproduction Steps

IChatClient client = runtime.AsChatClient("us.anthropic.claude-3-7-sonnet-20250219-v1:0");

 ChatOptions chatOptions = new ChatOptions();
 
  AITool toolInLine = MyTools.GetAITestTool();

  chatOptions.Tools.Add(toolInLine);

 client.GetStreamingResponseAsync(messages,chatOptions);

Possible Solution

No response

Additional Information/Context

No response

AWS .NET SDK and/or Package version used

AWSSDK.Extensions.Bedrock.MEAI - 4.0.0-preview.11

Targeted .NET Platform

.NET Core 3.1

Operating System and version

Windows 11

@cristiursachi cristiursachi added bug This issue is a bug. needs-triage This issue or PR still needs to be triaged. labels Mar 28, 2025
@ashishdhingra ashishdhingra self-assigned this Mar 28, 2025
@ashishdhingra ashishdhingra added needs-reproduction This issue needs reproduction. p2 This is a standard priority issue and removed needs-triage This issue or PR still needs to be triaged. labels Mar 28, 2025
@ashishdhingra
Copy link
Contributor

ashishdhingra commented Mar 28, 2025

@cristiursachi Good morning. Thanks for opening the GitHub issue. Reproducible using below code as an example:

using Amazon.BedrockRuntime;
using Microsoft.Extensions.AI;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Threading;
using System.Threading.Tasks;

namespace BedRockMEAITest
{
    internal class Program
    {
        delegate string GetWeather();

        static async Task Main(string[] args)
        {
            // Enable verbose logging
            Amazon.AWSConfigs.LoggingConfig.LogResponses = Amazon.ResponseLoggingOption.Always;
            Amazon.AWSConfigs.LoggingConfig.LogTo = Amazon.LoggingOptions.Console;
            Amazon.AWSConfigs.AddTraceListener("Amazon", new System.Diagnostics.ConsoleTraceListener());

            var runtime = new AmazonBedrockRuntimeClient();
            IChatClient chatClient = runtime.AsChatClient("us.anthropic.claude-3-7-sonnet-20250219-v1:0");

            GetWeather weatherDelegate = () => { return (new Random()).NextDouble() > 0.5 ? "It's sunny" : "It's raining"; };
            AITool aiTool = AIFunctionFactory.Create(weatherDelegate);

            ChatOptions chatOptions = new ChatOptions
            {
                Tools = new List<AITool> { aiTool }
            };

            await foreach (var response in chatClient.GetStreamingResponseAsync("Is this working?", chatOptions))
            {
                Console.Write(response.Text);
            }
        }
    }
}

It gives below error:

...
AWSSDKUtils 33|2025-03-28T17:10:53.655Z|INFO|Starting a process with the following ProcessInfo: UseShellExecute - False RedirectStandardError - True, RedirectStandardOutput - True, CreateNoWindow - True
AWSSDKUtils 34|2025-03-28T17:10:53.957Z|DEBUG|Process started
ProcessAWSCredentials 35|2025-03-28T17:10:55.849Z|INFO|Process ends with exitcode - 0
AWSSDKUtils 36|2025-03-28T17:10:56.090Z|DEBUG|Double encoded /model/{modelId}/converse-stream with endpoint https://bedrock-runtime.us-east-2.amazonaws.com/ for canonicalization: /model/us.anthropic.claude-3-7-sonnet-20250219-v1%253A0/converse-stream
AmazonBedrockRuntimeClient 37|2025-03-28T17:10:56.991Z|ERROR|An exception of type HttpErrorResponseException was handled in ErrorHandler. --> Amazon.Runtime.Internal.HttpErrorResponseException: Exception of type 'Amazon.Runtime.Internal.HttpErrorResponseException' was thrown.
   at Amazon.Runtime.HttpWebRequestMessage.ProcessHttpResponseMessage(HttpResponseMessage responseMessage)
   at Amazon.Runtime.HttpWebRequestMessage.GetResponseAsync(CancellationToken cancellationToken)
   at Amazon.Runtime.Internal.HttpHandler`1.InvokeAsync[T](IExecutionContext executionContext)
   at Amazon.Runtime.Internal.Unmarshaller.InvokeAsync[T](IExecutionContext executionContext)
   at Amazon.Runtime.Internal.ErrorHandler.InvokeAsync[T](IExecutionContext executionContext)
AmazonBedrockRuntimeClient 38|2025-03-28T17:10:57.138Z|ERROR|Received error response: [{"message":"The json schema definition at toolConfig.tools.0.toolSpec.inputSchema is invalid. Fix the following errors and try again: $.properties: null found, object expected"}] --> Amazon.BedrockRuntime.Model.ValidationException: The json schema definition at toolConfig.tools.0.toolSpec.inputSchema is invalid. Fix the following errors and try again: $.properties: null found, object expected
 ---> Amazon.Runtime.Internal.HttpErrorResponseException: Exception of type 'Amazon.Runtime.Internal.HttpErrorResponseException' was thrown.
   at Amazon.Runtime.HttpWebRequestMessage.ProcessHttpResponseMessage(HttpResponseMessage responseMessage)
   at Amazon.Runtime.HttpWebRequestMessage.GetResponseAsync(CancellationToken cancellationToken)
   at Amazon.Runtime.Internal.HttpHandler`1.InvokeAsync[T](IExecutionContext executionContext)
   at Amazon.Runtime.Internal.Unmarshaller.InvokeAsync[T](IExecutionContext executionContext)
   at Amazon.Runtime.Internal.ErrorHandler.InvokeAsync[T](IExecutionContext executionContext)
   --- End of inner exception stack trace ---
AmazonBedrockRuntimeClient 39|2025-03-28T17:10:57.152Z|ERROR|ValidationException making request ConverseStreamRequest to https://bedrock-runtime.us-east-2.amazonaws.com/. Attempt 1. --> Amazon.BedrockRuntime.Model.ValidationException: The json schema definition at toolConfig.tools.0.toolSpec.inputSchema is invalid. Fix the following errors and try again: $.properties: null found, object expected
 ---> Amazon.Runtime.Internal.HttpErrorResponseException: Exception of type 'Amazon.Runtime.Internal.HttpErrorResponseException' was thrown.
   at Amazon.Runtime.HttpWebRequestMessage.ProcessHttpResponseMessage(HttpResponseMessage responseMessage)
   at Amazon.Runtime.HttpWebRequestMessage.GetResponseAsync(CancellationToken cancellationToken)
   at Amazon.Runtime.Internal.HttpHandler`1.InvokeAsync[T](IExecutionContext executionContext)
   at Amazon.Runtime.Internal.Unmarshaller.InvokeAsync[T](IExecutionContext executionContext)
   at Amazon.Runtime.Internal.ErrorHandler.InvokeAsync[T](IExecutionContext executionContext)
   --- End of inner exception stack trace ---
   at Amazon.Runtime.Internal.HttpErrorResponseExceptionHandler.HandleExceptionStream(IRequestContext requestContext, IWebResponseData httpErrorResponse, HttpErrorResponseException exception, Stream responseStream)
   at Amazon.Runtime.Internal.HttpErrorResponseExceptionHandler.HandleExceptionAsync(IExecutionContext executionContext, HttpErrorResponseException exception)
   at Amazon.Runtime.Internal.ExceptionHandler`1.HandleAsync(IExecutionContext executionContext, Exception exception)
   at Amazon.Runtime.Internal.ErrorHandler.ProcessExceptionAsync(IExecutionContext executionContext, Exception exception)
   at Amazon.Runtime.Internal.ErrorHandler.InvokeAsync[T](IExecutionContext executionContext)
   at Amazon.Runtime.Internal.CallbackHandler.InvokeAsync[T](IExecutionContext executionContext)
   at Amazon.Runtime.Internal.Signer.InvokeAsync[T](IExecutionContext executionContext)
   at Amazon.Runtime.Internal.EndpointDiscoveryHandler.InvokeAsync[T](IExecutionContext executionContext)
   at Amazon.Runtime.Internal.EndpointDiscoveryHandler.InvokeAsync[T](IExecutionContext executionContext)
   at Amazon.Runtime.Internal.RetryHandler.InvokeAsync[T](IExecutionContext executionContext)

If we remove addition of Tools, then it works fine giving below output:

Yes, this is working! I'm here and ready to help you with any questions or tasks you might have. What can I assist you with today?

Even if we specify AdditionalProperties while creating tool, as shown below:

...
GetWeather weatherDelegate = () => { return (new Random()).NextDouble() > 0.5 ? "It's sunny" : "It's raining"; };
AITool aiTool = AIFunctionFactory.Create(weatherDelegate, 
    new AIFunctionFactoryOptions()
    {
        Name = "WeatherAITool", 
        Description = "Weather AI Tool",
        AdditionalProperties = new Dictionary<string, object>() { { "dummyproperty" , "dummyValue" } }
    }
);
ChatOptions chatOptions = new ChatOptions() { Tools = new List<AITool>() };
chatOptions.Tools.Add(aiTool);
...

While initializing ToolConfig here, the properties JsonElement in JsonSchema is an empty object:

ValueKind = Object : "{
  "title": "WeatherAITool",
  "description": "Weather AI Tool",
  "type": "object",
  "properties": {}
}"

Looks like an issue with Microsoft.Extensions.AI package (used version 9.3.0-preview.1.25161.3).

Needs review with the team.

Similar issues:

Possible Fix: (working)
Change code here to:

...
            Dictionary<string, Document> inputSchema = new()
            {
                ["type"] = new Document("object"),
                ["required"] = new Document(required),
            };
            if (inputs.Type != DocumentType.Null) inputSchema["properties"] = inputs;

            return new Tool()
            {
                ToolSpec = new ToolSpecification()
                {
                    Name = f.Name,
                    Description = !string.IsNullOrEmpty(f.Description) ? f.Description : f.Name,
                    InputSchema = new()
                    {
                        Json = new(inputSchema)
                    },
                },
            };
        }).ToList();
...

@cristiursachi Could you please share how you are creating AITool in your code:

...
  AITool toolInLine = MyTools.GetAITestTool();
  chatOptions.Tools.Add(toolInLine);
...

Thanks,
Ashish

@ashishdhingra ashishdhingra added needs-review and removed needs-reproduction This issue needs reproduction. labels Mar 28, 2025
@cristiursachi
Copy link
Author

cristiursachi commented Mar 31, 2025

Sure, my code to create AITool:

` public static AITool GetAITestTool()
{
return AIFunctionFactory.Create(ExecuteCommand,
"SomeFunction",
"SomeFunction description");

}

public static async Task<string> ExecuteCommand(string[] arguments)
{
     return "test";
 }`

@cristiursachi
Copy link
Author

I tested your Possible Fix above. While I do not get the error anymore, the tool is not called (when it should).

@ashishdhingra ashishdhingra removed their assignment Apr 3, 2025
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. Extensions p2 This is a standard priority issue queued
Projects
None yet
Development

No branches or pull requests

2 participants