I'm trying to use the .NET AWS Bedrock Client for tools calling. One thing I can't wrap my head around is how to pass the JSON schema of the tool, if I have the schema as a string.
So this is how I configure the tool:
var jsonSchemaString = """
{
"type":"object",
"required":[
"data",
"something",
"responses"
],
...more JSON schema
}
""";
return new ToolConfiguration
{
ToolChoice = new ToolChoice
{
Tool = new SpecificToolChoice
{
Name = "json_processor"
}
},
Tools =
[
new Tool
{
ToolSpec = new ToolSpecification
{
Name = "json_processor",
Description = "Processes well-structured JSON.",
InputSchema = new ToolInputSchema
{
Json = jsonSchemaString,
},
}
}
]
};
I've tried different ways of configuring the InputSchema. This particular way will throw an exception like:
Amazon.BedrockRuntime.Model.ValidationException
The format of the value at toolConfig.tools.0.toolSpec.inputSchema.json is invalid. Provide a json object for the field and try again.
And if I look at the actual request that is made, it looks like the input schema is double encoded like:
"tools":[{"toolSpec":{"description":"Processes well-structured JSON.","inputSchema":{"json":"{\\n \\"type\\": \\"object\\",\\n \\"required\\": [\\n \\
Not sure what to do here? The only way I've managed to configure it is by creating an object
like this:
var document = Document.FromObject(new
{
type = "object",
required = new List<object>
{
"data",
"something",
"responses"
},
...
});
I'm trying to use the .NET AWS Bedrock Client for tools calling. One thing I can't wrap my head around is how to pass the JSON schema of the tool, if I have the schema as a string.
So this is how I configure the tool:
var jsonSchemaString = """
{
"type":"object",
"required":[
"data",
"something",
"responses"
],
...more JSON schema
}
""";
return new ToolConfiguration
{
ToolChoice = new ToolChoice
{
Tool = new SpecificToolChoice
{
Name = "json_processor"
}
},
Tools =
[
new Tool
{
ToolSpec = new ToolSpecification
{
Name = "json_processor",
Description = "Processes well-structured JSON.",
InputSchema = new ToolInputSchema
{
Json = jsonSchemaString,
},
}
}
]
};
I've tried different ways of configuring the InputSchema. This particular way will throw an exception like:
Amazon.BedrockRuntime.Model.ValidationException
The format of the value at toolConfig.tools.0.toolSpec.inputSchema.json is invalid. Provide a json object for the field and try again.
And if I look at the actual request that is made, it looks like the input schema is double encoded like:
"tools":[{"toolSpec":{"description":"Processes well-structured JSON.","inputSchema":{"json":"{\\n \\"type\\": \\"object\\",\\n \\"required\\": [\\n \\
Not sure what to do here? The only way I've managed to configure it is by creating an object
like this:
var document = Document.FromObject(new
{
type = "object",
required = new List<object>
{
"data",
"something",
"responses"
},
...
});
Share
Improve this question
asked Mar 14 at 13:37
JoelJoel
9,00812 gold badges70 silver badges142 bronze badges
1 Answer
Reset to default 0AWS SDK provides JsonMapper
var jsonSchemaObject = JsonMapper.ToObject(jsonSchema);
new ToolSpecification
{
InputSchema = new ToolInputSchema { Json = Document.FromObject(jsonSchemaObject) }
}