Open jdempster opened 4 months ago
Hi @jdempster, sorry to hear about your issues. At this time the PHP SDK expects objects to be provided as associative array and also objects are deserialized as associative arrays. I tried to get the validation error and on my local I was not able to, so that I would like you to please provide a complete reproducible code where I can see more details. Also, would you please be able to enable debug logs by passing the debug flag to the client set to true. As follow:
$client = new BedrockRuntimeClient([
'region' => 'us-east-1',
'debug' => true
]);
Also, the following sample code did not cause the client validation error you are getting:
<?php
use Aws\BedrockRuntime\BedrockRuntimeClient;
require '../vendor/autoload.php';
$client = new BedrockRuntimeClient([
'region' => 'us-east-1'
]);
$result = $client->converse([
'modelId' => 'MODEL-ID',
'messages' => [
[
'role' => 'user',
'content' => [
[
'text' => 'Hi, how are you doing???'
]
]
]
],
'toolConfig' => [
'tools' => [
[
'toolSpec' => [
'name' => 'TestSpec',
'inputSchema' => [
'json' => [
]
]
]
]
]
]
]);
print_r($result->toArray());
Please make sure you redact any sensitive information and I look forward to your response.
Thanks!
The example provided does indeed cause the error. I've copied pasted, added the model, and updated the region.
<?php
use Aws\BedrockRuntime\BedrockRuntimeClient;
require './vendor/autoload.php';
$client = new BedrockRuntimeClient([
'region' => 'eu-west-2',
]);
$result = $client->converse([
'modelId' => 'anthropic.claude-3-sonnet-20240229-v1:0',
'messages' => [
[
'role' => 'user',
'content' => [
[
'text' => 'Hi, how are you doing???',
],
],
],
],
'toolConfig' => [
'tools' => [
[
'toolSpec' => [
'name' => 'TestSpec',
'inputSchema' => [
'json' => [
],
],
],
],
],
],
]);
print_r($result->toArray());
Fatal error: Uncaught exception 'Aws\BedrockRuntime\Exception\BedrockRuntimeException' with message 'Error executing "Converse" on "https://bedrock-runtime.eu-west-2.amazonaws.com/model/anthropic.claude-3-sonnet-20240229-v1%3A0/converse"; AWS HTTP error: Client error: `POST https://bedrock-runtime.eu-west-2.amazonaws.com/model/anthropic.claude-3-sonnet-20240229-v1%3A0/converse` resulted in a `400 Bad Request` response:
{"message":"The format of the value at toolConfig.tools.0.toolSpec.inputSchema.json is invalid. Provide a json object fo (truncated...)
ValidationException (client): The format of the value at toolConfig.tools.0.toolSpec.inputSchema.json is invalid. Provide a json object for the field and try again. - {"message":"The format of the value at toolConfig.tools.0.toolSpec.inputSchema.json is invalid. Provide a json object for the field and try again."}'
@jdempster, it looks like the validation is failing at service side and therefore I was not able to reproduce it. This validation should have been caught at client side if the values provided are invalid. I will investigate this internally and get back to you as soon as possible.
Thanks!
@jdempster I am not sure what could be causing this at your end. Did you make sure you are using a most recent SDK version?. I just tried again and I was unable to reproduce the error. My previous code failed because I did not specify the type for the json parameter, but here is an updated sample code:
<?php
use Aws\BedrockRuntime\BedrockRuntimeClient;
require '../vendor/autoload.php';
$client = new BedrockRuntimeClient([
'region' => 'us-east-1'
]);
$result = $client->converse([
'modelId' => 'anthropic.claude-3-sonnet-20240229-v1:0',
'messages' => [
[
'role' => 'user',
'content' => [
[
'text' => 'Hi, how are you doing???'
]
]
]
],
'toolConfig' => [
'tools' => [
[
'toolSpec' => [
'name' => 'TestSpec',
'inputSchema' => [
'json' => [
'type' => 'object',
]
]
]
]
]
]
]);
print_r($result->toArray());
Here is my result:
Array
(
[output] => Array
(
[message] => Array
(
[role] => assistant
[content] => Array
(
[0] => Array
(
[text] => I'm doing well, thanks for asking!
)
)
)
)
[stopReason] => end_turn
[usage] => Array
(
[inputTokens] => 196
[outputTokens] => 12
[totalTokens] => 208
)
[metrics] => Array
(
[latencyMs] => 1195
)
[@metadata] => Array
(
[statusCode] => 200
[effectiveUri] => https://bedrock-runtime.us-east-1.amazonaws.com/model/anthropic.claude-3-sonnet-20240229-v1%3A0/converse
[headers] => Array
(
[date] => Tue, 23 Jul 2024 17:03:33 GMT
[content-type] => application/json
[content-length] => 218
[connection] => keep-alive
[x-amzn-requestid] => req-id
)
[transferStats] => Array
(
[http] => Array
(
[0] => Array
(
)
)
)
)
)
Do you think is there anything I am missing here?
I look forward to your response.
Thanks!
This issue has not recieved a response in 1 week. If you want to keep this issue open, please just leave a comment below and auto-close will be canceled.
How’s the investigation going? I’ve susessfully created a client using guzzle and the sdk for auth. Where I create the payloads using objects.
Hi @jdempster, did you see my latest message here? It looks like you need to specify the type for the json parameter, which you are not according to the logs you have provided. For example, I see this in your debug logs:
request.body was set to {"messages":[{"role":"user","content":[{"text":"Hi, how are you doing???"}]}],"toolConfig":{"tools":[{"toolSpec":{"name":"TestSpec","inputSchema":{"json":[]}}}]}}
You can see that the json is parameter is being sent empty, and as I said you need to specify the type, which in this case should be set to object
. Please see my latest sample code.
Thanks!
This is because the AI executes the tool with an empty object. But the PHP SDK decodes this into an empty array. Causing an issue on the second request where we include the response from the AI in the messages.
<?php
use Aws\BedrockRuntime\BedrockRuntimeClient;
require './vendor/autoload.php';
$body = [
'modelId' => 'anthropic.claude-3-sonnet-20240229-v1:0',
'system' => [
[
'text' => 'You are a helpful bot.',
],
],
'messages' => [
[
'role' => 'user',
'content' => [
[
'text' => 'Hello, please tell me a fact',
],
],
],
],
'toolConfig' => [
'tools' => [
[
'toolSpec' => [
'name' => 'factGenerator',
'inputSchema' => [
'json' => [
'type' => 'object',
],
],
],
],
],
],
];
$client = new BedrockRuntimeClient([
'region' => 'us-east-1',
'debug' => true,
]);
$result = $client->converse($body);
$toolUseId = data_get($result->toArray(), 'output.message.content.1.toolUse.toolUseId');
$body['messages'][] = data_get($result->toArray(), 'output.message');
$body['messages'][] = [
'role' => 'user',
'content' => [
[
'toolResult' => [
'toolUseId' => $toolUseId,
'status' => 'success',
'content' => [
'json' => [
'fact' => 'The sky is blue.',
],
],
],
],
],
];
$client->converse($body);
print_r($result->toArray());
Log
-> Entering step init, name 'idempotency_auto_fill'
---------------------------------------------------
command was set to array(3) {
["instance"]=>
string(32) "000000000000000c0000000000000000"
["name"]=>
string(8) "Converse"
["params"]=>
array(6) {
["modelId"]=>
string(39) "anthropic.claude-3-sonnet-20240229-v1:0"
["system"]=>
array(1) {
[0]=>
array(1) {
["text"]=>
string(22) "You are a helpful bot."
}
}
["messages"]=>
array(1) {
[0]=>
array(2) {
["role"]=>
string(4) "user"
["content"]=>
array(1) {
[0]=>
array(1) {
["text"]=>
string(28) "Hello, please tell me a fact"
}
}
}
}
["toolConfig"]=>
array(1) {
["tools"]=>
array(1) {
[0]=>
array(1) {
["toolSpec"]=>
array(2) {
["name"]=>
string(13) "factGenerator"
["inputSchema"]=>
array(1) {
["json"]=>
array(1) {
["type"]=>
string(6) "object"
}
}
}
}
}
}
["@http"]=>
array(1) {
["debug"]=>
resource(302) of type (stream)
}
["@context"]=>
array(0) {
}
}
}
request was set to array(0) {
}
-> Entering step validate, name 'validation'
--------------------------------------------
no changes
-> Entering step build, name 'auth-selection'
---------------------------------------------
command.params.@context.signature_version was set to v4
-> Entering step build, name 'endpoint-resolution'
--------------------------------------------------
no changes
-> Entering step build, name 'builder'
--------------------------------------
request.instance was set to 00000000000000570000000000000000
request.method was set to POST
request.headers was set to array(3) {
["X-Amz-Security-Token"]=>
string(7) "[TOKEN]"
["Host"]=>
array(1) {
[0]=>
string(39) "bedrock-runtime.us-east-1.amazonaws.com"
}
["Content-Type"]=>
array(1) {
[0]=>
string(16) "application/json"
}
}
request.body was set to {"system":[{"text":"You are a helpful bot."}],"messages":[{"role":"user","content":[{"text":"Hello, please tell me a fact"}]}],"toolConfig":{"tools":[{"toolSpec":{"name":"factGenerator","inputSchema":{"json":{"type":"object"}}}}]}}
request.scheme was set to https
request.path was set to /model/anthropic.claude-3-sonnet-20240229-v1%3A0/converse
-> Entering step build, name 'ApiCallMonitoringMiddleware'
----------------------------------------------------------
no changes
-> Entering step build, name ''
-------------------------------
request.instance changed from 00000000000000570000000000000000 to 00000000000001060000000000000000
request.headers.X-Amz-User-Agent was set to array(1) {
[0]=>
string(59) "aws-sdk-php/3.319.4 ua/2.0 OS/Darwin#23.6.0 lang/php#8.1.29"
}
request.headers.User-Agent was set to array(1) {
[0]=>
string(59) "aws-sdk-php/3.319.4 ua/2.0 OS/Darwin#23.6.0 lang/php#8.1.29"
}
-> Entering step build, name 'endpoint_parameter'
-------------------------------------------------
no changes
-> Entering step build, name 'EndpointDiscoveryMiddleware'
----------------------------------------------------------
no changes
-> Entering step build, name 'request-compression'
--------------------------------------------------
no changes
-> Entering step build, name 'recursion-detection'
--------------------------------------------------
no changes
-> Entering step sign, name 'StreamRequestPayloadMiddleware'
------------------------------------------------------------
no changes
-> Entering step sign, name 'invocation-id'
-------------------------------------------
request.instance changed from 00000000000001060000000000000000 to 00000000000000ff0000000000000000
request.headers.aws-sdk-invocation-id was set to array(1) {
[0]=>
string(32) "4b8db3bcc928194b16928887d0588b3b"
}
-> Entering step sign, name 'retry'
-----------------------------------
request.instance changed from 00000000000000ff0000000000000000 to 00000000000001070000000000000000
request.headers.aws-sdk-retry was set to array(1) {
[0]=>
string(3) "0/0"
}
-> Entering step sign, name 'signer'
------------------------------------
request.instance changed from 00000000000001070000000000000000 to 00000000000000dd0000000000000000
request.headers.X-Amz-Date was set to array(1) {
[0]=>
string(16) "20240814T100436Z"
}
request.headers.Authorization was set to array(1) {
[0]=>
string(233) "AWS4-HMAC-SHA256 Credential=[KEY]/20240814/us-east-1/bedrock/aws4_request, SignedHeaders=host;x-amz-date;x-amz-security-token;x-amz-user-agent, Signature=[SIGNATURE]
}
-> Entering step attempt, name 'ApiCallAttemptMonitoringMiddleware'
-------------------------------------------------------------------
no changes
* Host bedrock-runtime.us-east-1.amazonaws.com:443 was resolved.
* IPv6: (none)
* IPv4: 34.196.47.193, 54.91.100.240, 34.198.53.146, 34.226.26.180, 52.205.81.175
* Trying 34.196.47.193:443...
* Connected to bedrock-runtime.us-east-1.amazonaws.com (34.196.47.193) port 443
* ALPN: curl offers http/1.1
* CAfile: /opt/homebrew/etc/openssl@3/cert.pem
* CApath: none
* SSL connection using TLSv1.3 / TLS_AES_128_GCM_SHA256 / x25519 / RSASSA-PSS
* ALPN: server accepted http/1.1
* Server certificate:
* subject: CN=bedrock-runtime.us-east-1.amazonaws.com
* start date: Sep 22 00:00:00 2023 GMT
* expire date: Oct 20 23:59:59 2024 GMT
* subjectAltName: host "bedrock-runtime.us-east-1.amazonaws.com" matched cert's "bedrock-runtime.us-east-1.amazonaws.com"
* issuer: C=US; O=Amazon; CN=Amazon RSA 2048 M02
* SSL certificate verify ok.
* Certificate level 0: Public key type RSA (2048/112 Bits/secBits), signed using sha256WithRSAEncryption
* Certificate level 1: Public key type RSA (2048/112 Bits/secBits), signed using sha256WithRSAEncryption
* Certificate level 2: Public key type RSA (2048/112 Bits/secBits), signed using sha256WithRSAEncryption
* using HTTP/1.x
> POST /model/anthropic.claude-3-sonnet-20240229-v1%3A0/converse HTTP/1.1
Host: bedrock-runtime.us-east-1.amazonaws.com
Content-Type: application/json
X-Amz-User-Agent: aws-sdk-php/3.319.4 ua/2.0 OS/Darwin#23.6.0 lang/php#8.1.29
aws-sdk-invocation-id: 4b8db3bcc928194b16928887d0588b3b
aws-sdk-retry: 0/0
X-Amz-Date: 20240814T100436Z
Authorization: AWS4-HMAC-SHA256 Credential=[KEY]/20240814/us-east-1/bedrock/aws4_request, SignedHeaders=host;x-amz-date;x-amz-security-token;x-amz-user-agent, Signature=[SIGNATURE]
User-Agent: aws-sdk-php/3.319.4 ua/2.0 OS/Darwin#23.6.0 lang/php#8.1.29 GuzzleHttp/7
Content-Length: 231
* upload completely sent off: 231 bytes
< HTTP/1.1 200 OK
< Date: Wed, 14 Aug 2024 10:04:37 GMT
< Content-Type: application/json
< Content-Length: 313
< Connection: keep-alive
< x-amzn-RequestId: 30331ccc-b286-4419-baa8-574bb4124d4d
<
* Connection #0 to host bedrock-runtime.us-east-1.amazonaws.com left intact
<- Leaving step attempt, name 'ApiCallAttemptMonitoringMiddleware'
------------------------------------------------------------------
result was set to array(2) {
["instance"]=>
string(32) "000000000000014e0000000000000000"
["data"]=>
array(5) {
["output"]=>
array(1) {
["message"]=>
array(2) {
["role"]=>
string(9) "assistant"
["content"]=>
array(2) {
[0]=>
array(1) {
["text"]=>
string(37) "Okay, let me generate a fact for you:"
}
[1]=>
array(1) {
["toolUse"]=>
array(3) {
["toolUseId"]=>
string(30) "tooluse_qrU_MEkkTo2mNHv11mr1-A"
["name"]=>
string(13) "factGenerator"
["input"]=>
array(0) {
}
}
}
}
}
}
["stopReason"]=>
string(8) "tool_use"
["usage"]=>
array(3) {
["inputTokens"]=>
int(203)
["outputTokens"]=>
int(47)
["totalTokens"]=>
int(250)
}
["metrics"]=>
array(1) {
["latencyMs"]=>
int(876)
}
["@metadata"]=>
array(4) {
["statusCode"]=>
int(200)
["effectiveUri"]=>
string(104) "https://bedrock-runtime.us-east-1.amazonaws.com/model/anthropic.claude-3-sonnet-20240229-v1%3A0/converse"
["headers"]=>
array(5) {
["date"]=>
string(29) "Wed, 14 Aug 2024 10:04:37 GMT"
["content-type"]=>
string(16) "application/json"
["content-length"]=>
string(3) "313"
["connection"]=>
string(10) "keep-alive"
["x-amzn-requestid"]=>
string(36) "30331ccc-b286-4419-baa8-574bb4124d4d"
}
["transferStats"]=>
array(0) {
}
}
}
}
Inclusive step time: 1.1625289916992
<- Leaving step sign, name 'signer'
-----------------------------------
no changes
Inclusive step time: 1.1625788211823
<- Leaving step sign, name 'retry'
----------------------------------
no changes
Inclusive step time: 1.1632709503174
<- Leaving step sign, name 'invocation-id'
------------------------------------------
result.data.@metadata.transferStats.http was set to array(1) {
[0]=>
array(0) {
}
}
Inclusive step time: 1.1633341312408
<- Leaving step sign, name 'StreamRequestPayloadMiddleware'
-----------------------------------------------------------
no changes
Inclusive step time: 1.163370847702
<- Leaving step build, name 'recursion-detection'
-------------------------------------------------
no changes
Inclusive step time: 1.16339802742
<- Leaving step build, name 'request-compression'
-------------------------------------------------
no changes
Inclusive step time: 1.1634230613708
<- Leaving step build, name 'EndpointDiscoveryMiddleware'
---------------------------------------------------------
no changes
Inclusive step time: 1.1634500026703
<- Leaving step build, name 'endpoint_parameter'
------------------------------------------------
no changes
Inclusive step time: 1.1634731292725
<- Leaving step build, name ''
------------------------------
no changes
Inclusive step time: 1.1635119915009
<- Leaving step build, name 'ApiCallMonitoringMiddleware'
---------------------------------------------------------
no changes
Inclusive step time: 1.1635468006134
<- Leaving step build, name 'builder'
-------------------------------------
no changes
Inclusive step time: 1.1638150215149
<- Leaving step build, name 'endpoint-resolution'
-------------------------------------------------
no changes
Inclusive step time: 1.165629863739
<- Leaving step build, name 'auth-selection'
--------------------------------------------
no changes
Inclusive step time: 1.1660118103027
<- Leaving step validate, name 'validation'
-------------------------------------------
no changes
Inclusive step time: 1.166218996048
<- Leaving step init, name 'idempotency_auto_fill'
--------------------------------------------------
no changes
Inclusive step time: 1.1663880348206
-> Entering step init, name 'idempotency_auto_fill'
---------------------------------------------------
command was set to array(3) {
["instance"]=>
string(32) "00000000000001340000000000000000"
["name"]=>
string(8) "Converse"
["params"]=>
array(6) {
["modelId"]=>
string(39) "anthropic.claude-3-sonnet-20240229-v1:0"
["system"]=>
array(1) {
[0]=>
array(1) {
["text"]=>
string(22) "You are a helpful bot."
}
}
["messages"]=>
array(3) {
[0]=>
array(2) {
["role"]=>
string(4) "user"
["content"]=>
array(1) {
[0]=>
array(1) {
["text"]=>
string(28) "Hello, please tell me a fact"
}
}
}
[1]=>
array(2) {
["role"]=>
string(9) "assistant"
["content"]=>
array(2) {
[0]=>
array(1) {
["text"]=>
string(37) "Okay, let me generate a fact for you:"
}
[1]=>
array(1) {
["toolUse"]=>
array(3) {
["toolUseId"]=>
string(30) "tooluse_qrU_MEkkTo2mNHv11mr1-A"
["name"]=>
string(13) "factGenerator"
["input"]=>
array(0) {
}
}
}
}
}
[2]=>
array(2) {
["role"]=>
string(4) "user"
["content"]=>
array(1) {
[0]=>
array(1) {
["toolResult"]=>
array(3) {
["toolUseId"]=>
string(30) "tooluse_qrU_MEkkTo2mNHv11mr1-A"
["status"]=>
string(7) "success"
["content"]=>
array(1) {
["json"]=>
array(1) {
["fact"]=>
string(16) "The sky is blue."
}
}
}
}
}
}
}
["toolConfig"]=>
array(1) {
["tools"]=>
array(1) {
[0]=>
array(1) {
["toolSpec"]=>
array(2) {
["name"]=>
string(13) "factGenerator"
["inputSchema"]=>
array(1) {
["json"]=>
array(1) {
["type"]=>
string(6) "object"
}
}
}
}
}
}
["@http"]=>
array(1) {
["debug"]=>
resource(338) of type (stream)
}
["@context"]=>
array(0) {
}
}
}
request was set to array(0) {
}
-> Entering step validate, name 'validation'
--------------------------------------------
no changes
-> Entering step build, name 'auth-selection'
---------------------------------------------
command.params.@context.signature_version was set to v4
-> Entering step build, name 'endpoint-resolution'
--------------------------------------------------
no changes
-> Entering step build, name 'builder'
--------------------------------------
request.instance was set to 00000000000000fd0000000000000000
request.method was set to POST
request.headers was set to array(3) {
["X-Amz-Security-Token"]=>
string(7) "[TOKEN]"
["Host"]=>
array(1) {
[0]=>
string(39) "bedrock-runtime.us-east-1.amazonaws.com"
}
["Content-Type"]=>
array(1) {
[0]=>
string(16) "application/json"
}
}
request.body was set to {"system":[{"text":"You are a helpful bot."}],"messages":[{"role":"user","content":[{"text":"Hello, please tell me a fact"}]},{"role":"assistant","content":[{"text":"Okay, let me generate a fact for you:"},{"toolUse":{"toolUseId":"tooluse_qrU_MEkkTo2mNHv11mr1-A","name":"factGenerator","input":[]}}]},{"role":"user","content":[{"toolResult":{"toolUseId":"tooluse_qrU_MEkkTo2mNHv11mr1-A","status":"success","content":{"json":{}}}}]}],"toolConfig":{"tools":[{"toolSpec":{"name":"factGenerator","inputSchema":{"json":{"type":"object"}}}}]}}
request.scheme was set to https
request.path was set to /model/anthropic.claude-3-sonnet-20240229-v1%3A0/converse
-> Entering step build, name 'ApiCallMonitoringMiddleware'
----------------------------------------------------------
no changes
-> Entering step build, name ''
-------------------------------
request.instance changed from 00000000000000fd0000000000000000 to 00000000000000c40000000000000000
request.headers.X-Amz-User-Agent was set to array(1) {
[0]=>
string(59) "aws-sdk-php/3.319.4 ua/2.0 OS/Darwin#23.6.0 lang/php#8.1.29"
}
request.headers.User-Agent was set to array(1) {
[0]=>
string(59) "aws-sdk-php/3.319.4 ua/2.0 OS/Darwin#23.6.0 lang/php#8.1.29"
}
-> Entering step build, name 'endpoint_parameter'
-------------------------------------------------
no changes
-> Entering step build, name 'EndpointDiscoveryMiddleware'
----------------------------------------------------------
no changes
-> Entering step build, name 'request-compression'
--------------------------------------------------
no changes
-> Entering step build, name 'recursion-detection'
--------------------------------------------------
no changes
-> Entering step sign, name 'StreamRequestPayloadMiddleware'
------------------------------------------------------------
no changes
-> Entering step sign, name 'invocation-id'
-------------------------------------------
request.instance changed from 00000000000000c40000000000000000 to 00000000000001060000000000000000
request.headers.aws-sdk-invocation-id was set to array(1) {
[0]=>
string(32) "babc8264e5515c07eb367baa5ee7d406"
}
-> Entering step sign, name 'retry'
-----------------------------------
request.instance changed from 00000000000001060000000000000000 to 000000000000011f0000000000000000
request.headers.aws-sdk-retry was set to array(1) {
[0]=>
string(3) "0/0"
}
-> Entering step sign, name 'signer'
------------------------------------
request.instance changed from 000000000000011f0000000000000000 to 00000000000000cb0000000000000000
request.headers.X-Amz-Date was set to array(1) {
[0]=>
string(16) "20240814T100437Z"
}
request.headers.Authorization was set to array(1) {
[0]=>
string(233) "AWS4-HMAC-SHA256 Credential=[KEY]/20240814/us-east-1/bedrock/aws4_request, SignedHeaders=host;x-amz-date;x-amz-security-token;x-amz-user-agent, Signature=[SIGNATURE]
}
-> Entering step attempt, name 'ApiCallAttemptMonitoringMiddleware'
-------------------------------------------------------------------
no changes
* Found bundle for host: 0x60000160d4a0 [serially]
* Re-using existing connection with host bedrock-runtime.us-east-1.amazonaws.com
> POST /model/anthropic.claude-3-sonnet-20240229-v1%3A0/converse HTTP/1.1
Host: bedrock-runtime.us-east-1.amazonaws.com
Content-Type: application/json
X-Amz-User-Agent: aws-sdk-php/3.319.4 ua/2.0 OS/Darwin#23.6.0 lang/php#8.1.29
aws-sdk-invocation-id: babc8264e5515c07eb367baa5ee7d406
aws-sdk-retry: 0/0
X-Amz-Date: 20240814T100437Z
Authorization: AWS4-HMAC-SHA256 Credential=[KEY]/20240814/us-east-1/bedrock/aws4_request, SignedHeaders=host;x-amz-date;x-amz-security-token;x-amz-user-agent, Signature=[SIGNATURE]
User-Agent: aws-sdk-php/3.319.4 ua/2.0 OS/Darwin#23.6.0 lang/php#8.1.29 GuzzleHttp/7
Content-Length: 537
* upload completely sent off: 537 bytes
< HTTP/1.1 400 Bad Request
< Date: Wed, 14 Aug 2024 10:04:37 GMT
< Content-Type: application/json
< Content-Length: 64
< Connection: keep-alive
< x-amzn-RequestId: 42e20882-62f1-42a3-ad76-4be7e7365efd
< x-amzn-ErrorType: SerializationException:http://internal.amazon.com/coral/com.amazon.coral.service/
<
* Connection #0 to host bedrock-runtime.us-east-1.amazonaws.com left intact
<- Leaving step attempt, name 'ApiCallAttemptMonitoringMiddleware'
------------------------------------------------------------------
error was set to array(13) {
["instance"]=>
string(32) "000000000000017c0000000000000000"
["class"]=>
string(52) "Aws\BedrockRuntime\Exception\BedrockRuntimeException"
["message"]=>
string(538) "Error executing "Converse" on "https://bedrock-runtime.us-east-1.amazonaws.com/model/anthropic.claude-3-sonnet-20240229-v1%3A0/converse"; AWS HTTP error: Client error: `POST https://bedrock-runtime.us-east-1.amazonaws.com/model/anthropic.claude-3-sonnet-20240229-v1%3A0/converse` resulted in a `400 Bad Request` response:
{"Message":"Start of structure or map found where not expected"}
SerializationException (client): Start of structure or map found where not expected - {"Message":"Start of structure or map found where not expected"}"
["file"]=>
string(80) "/Volumes/Sites/test/vendor/aws/aws-sdk-php/src/WrappedHttpHandler.php"
["line"]=>
int(196)
["trace"]=>
string(2291) "#0 /Volumes/Sites/test/vendor/aws/aws-sdk-php/src/WrappedHttpHandler.php(98): Aws\WrappedHttpHandler->parseError(Array, Object(GuzzleHttp\Psr7\Request), Object(Aws\Command), Array)
#1 /Volumes/Sites/test/vendor/guzzlehttp/promises/src/Promise.php(209): Aws\WrappedHttpHandler->Aws\{closure}(Array)
#2 /Volumes/Sites/test/vendor/guzzlehttp/promises/src/Promise.php(174): GuzzleHttp\Promise\Promise::callHandler(2, Array, NULL)
#3 /Volumes/Sites/test/vendor/guzzlehttp/promises/src/RejectedPromise.php(49): GuzzleHttp\Promise\Promise::GuzzleHttp\Promise\{closure}(Array)
#4 /Volumes/Sites/test/vendor/guzzlehttp/promises/src/TaskQueue.php(52): GuzzleHttp\Promise\RejectedPromise::GuzzleHttp\Promise\{closure}()
#5 /Volumes/Sites/test/vendor/guzzlehttp/guzzle/src/Handler/CurlMultiHandler.php(163): GuzzleHttp\Promise\TaskQueue->run()
#6 /Volumes/Sites/test/vendor/guzzlehttp/guzzle/src/Handler/CurlMultiHandler.php(189): GuzzleHttp\Handler\CurlMultiHandler->tick()
#7 /Volumes/Sites/test/vendor/guzzlehttp/promises/src/Promise.php(251): GuzzleHttp\Handler\CurlMultiHandler->execute(true)
#8 /Volumes/Sites/test/vendor/guzzlehttp/promises/src/Promise.php(227): GuzzleHttp\Promise\Promise->invokeWaitFn()
#9 /Volumes/Sites/test/vendor/guzzlehttp/promises/src/Promise.php(272): GuzzleHttp\Promise\Promise->waitIfPending()
#10 /Volumes/Sites/test/vendor/guzzlehttp/promises/src/Promise.php(229): GuzzleHttp\Promise\Promise->invokeWaitList()
#11 /Volumes/Sites/test/vendor/guzzlehttp/promises/src/Promise.php(272): GuzzleHttp\Promise\Promise->waitIfPending()
#12 /Volumes/Sites/test/vendor/guzzlehttp/promises/src/Promise.php(229): GuzzleHttp\Promise\Promise->invokeWaitList()
#13 /Volumes/Sites/test/vendor/guzzlehttp/promises/src/Promise.php(69): GuzzleHttp\Promise\Promise->waitIfPending()
#14 /Volumes/Sites/test/vendor/aws/aws-sdk-php/src/AwsClientTrait.php(58): GuzzleHttp\Promise\Promise->wait()
#15 /Volumes/Sites/test/vendor/aws/aws-sdk-php/src/AwsClientTrait.php(86): Aws\AwsClient->execute(Object(Aws\Command))
#16 /Volumes/Sites/test/test.php(65): Aws\AwsClient->__call('converse', Array)
#17 {main}"
["type"]=>
string(6) "client"
["code"]=>
string(22) "SerializationException"
["requestId"]=>
string(36) "42e20882-62f1-42a3-ad76-4be7e7365efd"
["statusCode"]=>
int(400)
["result"]=>
NULL
["request"]=>
array(6) {
["instance"]=>
string(32) "00000000000000cb0000000000000000"
["method"]=>
string(4) "POST"
["headers"]=>
array(9) {
["X-Amz-Security-Token"]=>
string(7) "[TOKEN]"
["Host"]=>
array(1) {
[0]=>
string(39) "bedrock-runtime.us-east-1.amazonaws.com"
}
["Content-Type"]=>
array(1) {
[0]=>
string(16) "application/json"
}
["X-Amz-User-Agent"]=>
array(1) {
[0]=>
string(59) "aws-sdk-php/3.319.4 ua/2.0 OS/Darwin#23.6.0 lang/php#8.1.29"
}
["User-Agent"]=>
array(1) {
[0]=>
string(59) "aws-sdk-php/3.319.4 ua/2.0 OS/Darwin#23.6.0 lang/php#8.1.29"
}
["aws-sdk-invocation-id"]=>
array(1) {
[0]=>
string(32) "babc8264e5515c07eb367baa5ee7d406"
}
["aws-sdk-retry"]=>
array(1) {
[0]=>
string(3) "0/0"
}
["X-Amz-Date"]=>
array(1) {
[0]=>
string(16) "20240814T100437Z"
}
["Authorization"]=>
array(1) {
[0]=>
string(233) "AWS4-HMAC-SHA256 Credential=[KEY]/20240814/us-east-1/bedrock/aws4_request, SignedHeaders=host;x-amz-date;x-amz-security-token;x-amz-user-agent, Signature=[SIGNATURE]
}
}
["body"]=>
string(537) "{"system":[{"text":"You are a helpful bot."}],"messages":[{"role":"user","content":[{"text":"Hello, please tell me a fact"}]},{"role":"assistant","content":[{"text":"Okay, let me generate a fact for you:"},{"toolUse":{"toolUseId":"tooluse_qrU_MEkkTo2mNHv11mr1-A","name":"factGenerator","input":[]}}]},{"role":"user","content":[{"toolResult":{"toolUseId":"tooluse_qrU_MEkkTo2mNHv11mr1-A","status":"success","content":{"json":{}}}}]}],"toolConfig":{"tools":[{"toolSpec":{"name":"factGenerator","inputSchema":{"json":{"type":"object"}}}}]}}"
["scheme"]=>
string(5) "https"
["path"]=>
string(57) "/model/anthropic.claude-3-sonnet-20240229-v1%3A0/converse"
}
["response"]=>
array(4) {
["instance"]=>
string(32) "000000000000011c0000000000000000"
["statusCode"]=>
int(400)
["headers"]=>
array(7) {
["X-Amz-Security-Token"]=>
string(7) "[TOKEN]"
["Date"]=>
array(1) {
[0]=>
string(29) "Wed, 14 Aug 2024 10:04:37 GMT"
}
["Content-Type"]=>
array(1) {
[0]=>
string(16) "application/json"
}
["Content-Length"]=>
array(1) {
[0]=>
string(2) "64"
}
["Connection"]=>
array(1) {
[0]=>
string(10) "keep-alive"
}
["x-amzn-RequestId"]=>
array(1) {
[0]=>
string(36) "42e20882-62f1-42a3-ad76-4be7e7365efd"
}
["x-amzn-ErrorType"]=>
array(1) {
[0]=>
string(81) "SerializationException:http://internal.amazon.com/coral/com.amazon.coral.service/"
}
}
["body"]=>
string(64) "{"Message":"Start of structure or map found where not expected"}"
}
}
Inclusive step time: 0.11638498306274
<- Leaving step sign, name 'signer'
-----------------------------------
no changes
Inclusive step time: 0.11650776863098
<- Leaving step sign, name 'retry'
----------------------------------
no changes
Inclusive step time: 0.11682915687561
<- Leaving step sign, name 'invocation-id'
------------------------------------------
no changes
Inclusive step time: 0.11694097518921
<- Leaving step sign, name 'StreamRequestPayloadMiddleware'
-----------------------------------------------------------
no changes
Inclusive step time: 0.11703395843506
<- Leaving step build, name 'recursion-detection'
-------------------------------------------------
no changes
Inclusive step time: 0.11711192131042
<- Leaving step build, name 'request-compression'
-------------------------------------------------
no changes
Inclusive step time: 0.11718606948853
<- Leaving step build, name 'EndpointDiscoveryMiddleware'
---------------------------------------------------------
no changes
Inclusive step time: 0.11725902557373
<- Leaving step build, name 'endpoint_parameter'
------------------------------------------------
no changes
Inclusive step time: 0.11733508110046
<- Leaving step build, name ''
------------------------------
no changes
Inclusive step time: 0.117436170578
<- Leaving step build, name 'ApiCallMonitoringMiddleware'
---------------------------------------------------------
no changes
Inclusive step time: 0.11752700805664
<- Leaving step build, name 'builder'
-------------------------------------
no changes
Inclusive step time: 0.11766910552979
<- Leaving step build, name 'endpoint-resolution'
-------------------------------------------------
no changes
Inclusive step time: 0.11797690391541
<- Leaving step build, name 'auth-selection'
--------------------------------------------
no changes
Inclusive step time: 0.11811709403992
<- Leaving step validate, name 'validation'
-------------------------------------------
no changes
Inclusive step time: 0.11820888519287
<- Leaving step init, name 'idempotency_auto_fill'
--------------------------------------------------
no changes
Inclusive step time: 0.1185610294342
Fatal error: Uncaught exception 'Aws\BedrockRuntime\Exception\BedrockRuntimeException' with message 'Error executing "Converse" on "https://bedrock-runtime.us-east-1.amazonaws.com/model/anthropic.claude-3-sonnet-20240229-v1%3A0/converse"; AWS HTTP error: Client error: `POST https://bedrock-runtime.us-east-1.amazonaws.com/model/anthropic.claude-3-sonnet-20240229-v1%3A0/converse` resulted in a `400 Bad Request` response:
{"Message":"Start of structure or map found where not expected"}
SerializationException (client): Start of structure or map found where not expected - {"Message":"Start of structure or map found where not expected"}'
GuzzleHttp\Exception\ClientException: Client error: `POST https://bedrock-runtime.us-east-1.amazonaws.com/model/anthropic.claude-3-sonnet-20240229-v1%3A0/converse` resulted in a `400 Bad Request` response:
{"Message":"Start of structure or map found where not expected"}
in /Volumes/Sites/test/vendor/guzzlehttp/guzzle/src/Exception/RequestException.php:113
Stack trace:
#0 /Volumes/Sites/test/vendor/guzzlehttp/guzzle/src/Middleware.php(72): GuzzleHttp\Exception\RequestException::create(Object(GuzzleHttp\Psr7\Request), Object(GuzzleHttp\Psr7\Response), NULL, Array, NULL)
#1 /Volumes/Sites/test/vendor/guzzlehttp/promises/src/Promise.php(209): GuzzleHttp\Middleware::GuzzleHttp\{closure}(Object(GuzzleHttp\Psr7\Response))
#2 /Volumes/Sites/test/vendor/guzzlehttp/promises/src/Promise.php(158): GuzzleHttp\Promise\Promise::callHandler(1, Object(GuzzleHttp\Psr7\Response), NULL)
#3 /Volumes/Sites/test/vendor/guzzlehttp/promises/src/TaskQueue.php(52): GuzzleHttp\Promise\Promise::GuzzleHttp\Promise\{closure}()
#4 /Volumes/Sites/test/vendor/guzzlehttp/guzzle/src/Handler/CurlMultiHandler.php(163): GuzzleHttp\Promise\TaskQueue->run()
#5 /Volumes/Sites/test/vendor/guzzlehttp/guzzle/src/Handler/CurlMultiHandler.php(189): GuzzleHttp\Handler\CurlMultiHandler->tick()
#6 /Volumes/Sites/test/vendor/guzzlehttp/promises/src/Promise.php(251): GuzzleHttp\Handler\CurlMultiHandler->execute(true)
#7 /Volumes/Sites/test/vendor/guzzlehttp/promises/src/Promise.php(227): GuzzleHttp\Promise\Promise->invokeWaitFn()
#8 /Volumes/Sites/test/vendor/guzzlehttp/promises/src/Promise.php(272): GuzzleHttp\Promise\Promise->waitIfPending()
#9 /Volumes/Sites/test/vendor/guzzlehttp/promises/src/Promise.php(229): GuzzleHttp\Promise\Promise->invokeWaitList()
#10 /Volumes/Sites/test/vendor/guzzlehttp/promises/src/Promise.php(272): GuzzleHttp\Promise\Promise->waitIfPending()
#11 /Volumes/Sites/test/vendor/guzzlehttp/promises/src/Promise.php(229): GuzzleHttp\Promise\Promise->invokeWaitList()
#12 /Volumes/Sites/test/vendor/guzzlehttp/promises/src/Promise.php(69): GuzzleHttp\Promise\Promise->waitIfPending()
#13 /Volumes/Sites/test/vendor/aws/aws-sdk-php/src/AwsClientTrait.php(58): GuzzleHttp\Promise\Promise->wait()
#14 /Volumes/Sites/test/vendor/aws/aws-sdk-php/src/AwsClientTrait.php(86): Aws\AwsClient->execute(Object(Aws\Command))
#15 /Volumes/Sites/test/test.php(65): Aws\AwsClient->__call('converse', Array)
#16 {main}
Next Aws\BedrockRuntime\Exception\BedrockRuntimeException: Error executing "Converse" on "https://bedrock-runtime.us-east-1.amazonaws.com/model/anthropic.claude-3-sonnet-20240229-v1%3A0/converse"; AWS HTTP error: Client error: `POST https://bedrock-runtime.us-east-1.amazonaws.com/model/anthropic.claude-3-sonnet-20240229-v1%3A0/converse` resulted in a `400 Bad Request` response:
{"Message":"Start of structure or map found where not expected"}
SerializationException (client): Start of structure or map found where not expected - {"Message":"Start of structure or map found where not expected"} in /Volumes/Sites/test/vendor/aws/aws-sdk-php/src/WrappedHttpHandler.php:196
Stack trace:
#0 /Volumes/Sites/test/vendor/aws/aws-sdk-php/src/WrappedHttpHandler.php(98): Aws\WrappedHttpHandler->parseError(Array, Object(GuzzleHttp\Psr7\Request), Object(Aws\Command), Array)
#1 /Volumes/Sites/test/vendor/guzzlehttp/promises/src/Promise.php(209): Aws\WrappedHttpHandler->Aws\{closure}(Array)
#2 /Volumes/Sites/test/vendor/guzzlehttp/promises/src/Promise.php(174): GuzzleHttp\Promise\Promise::callHandler(2, Array, NULL)
#3 /Volumes/Sites/test/vendor/guzzlehttp/promises/src/RejectedPromise.php(49): GuzzleHttp\Promise\Promise::GuzzleHttp\Promise\{closure}(Array)
#4 /Volumes/Sites/test/vendor/guzzlehttp/promises/src/TaskQueue.php(52): GuzzleHttp\Promise\RejectedPromise::GuzzleHttp\Promise\{closure}()
#5 /Volumes/Sites/test/vendor/guzzlehttp/guzzle/src/Handler/CurlMultiHandler.php(163): GuzzleHttp\Promise\TaskQueue->run()
#6 /Volumes/Sites/test/vendor/guzzlehttp/guzzle/src/Handler/CurlMultiHandler.php(189): GuzzleHttp\Handler\CurlMultiHandler->tick()
#7 /Volumes/Sites/test/vendor/guzzlehttp/promises/src/Promise.php(251): GuzzleHttp\Handler\CurlMultiHandler->execute(true)
#8 /Volumes/Sites/test/vendor/guzzlehttp/promises/src/Promise.php(227): GuzzleHttp\Promise\Promise->invokeWaitFn()
#9 /Volumes/Sites/test/vendor/guzzlehttp/promises/src/Promise.php(272): GuzzleHttp\Promise\Promise->waitIfPending()
#10 /Volumes/Sites/test/vendor/guzzlehttp/promises/src/Promise.php(229): GuzzleHttp\Promise\Promise->invokeWaitList()
#11 /Volumes/Sites/test/vendor/guzzlehttp/promises/src/Promise.php(272): GuzzleHttp\Promise\Promise->waitIfPending()
#12 /Volumes/Sites/test/vendor/guzzlehttp/promises/src/Promise.php(229): GuzzleHttp\Promise\Promise->invokeWaitList()
#13 /Volumes/Sites/test/vendor/guzzlehttp/promises/src/Promise.php(69): GuzzleHttp\Promise\Promise->waitIfPending()
#14 /Volumes/Sites/test/vendor/aws/aws-sdk-php/src/AwsClientTrait.php(58): GuzzleHttp\Promise\Promise->wait()
#15 /Volumes/Sites/test/vendor/aws/aws-sdk-php/src/AwsClientTrait.php(86): Aws\AwsClient->execute(Object(Aws\Command))
#16 /Volumes/Sites/test/test.php(65): Aws\AwsClient->__call('converse', Array)
#17 {main}
thrown in /Volumes/Sites/test/vendor/aws/aws-sdk-php/src/WrappedHttpHandler.php on line 196
Describe the bug
Bedrock toolSpec requires inputSchema to be an object, but SDK wants an assoc array, which forces an input to be specified.
Expected Behavior
Accept null, or empty object
Current Behavior
Passing an empty object produces the following error
Passing an empty array produces the following error
Reproduction Steps
Possible Solution
Additional Information/Context
There is also an issue where the return value of the tool use wants to return an empty object, but when unserialised in php becomes an empty array. When trying to continue the converstaion this then causes the following error.
SDK version used
3.316
Environment details (Version of PHP (
php -v
)? OS name and version, etc.)MacOS php8.1