-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Bedrock tool use inputSchema required but empty object fails validation #2962
Comments
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());
Debug Logs-> Entering step init, name 'idempotency_auto_fill'
---------------------------------------------------
command was set to array(3) {
["instance"]=>
string(32) "000000000000000c0000000000000000"
["name"]=>
string(8) "Converse"
["params"]=>
array(5) {
["modelId"]=>
string(39) "anthropic.claude-3-sonnet-20240229-v1:0"
["messages"]=>
array(1) {
[0]=>
array(2) {
["role"]=>
string(4) "user"
["content"]=>
array(1) {
[0]=>
array(1) {
["text"]=>
string(24) "Hi, how are you doing???"
}
}
}
}
["toolConfig"]=>
array(1) {
["tools"]=>
array(1) {
[0]=>
array(1) {
["toolSpec"]=>
array(2) {
["name"]=>
string(8) "TestSpec"
["inputSchema"]=>
array(1) {
["json"]=>
array(0) {
}
}
}
}
}
}
["@http"]=>
array(1) {
["debug"]=>
resource(300) 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'
---------------------------------------------
no changes
-> 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.eu-west-2.amazonaws.com"
}
["Content-Type"]=>
array(1) {
[0]=>
string(16) "application/json"
}
}
request.body was set to {"messages":[{"role":"user","content":[{"text":"Hi, how are you doing???"}]}],"toolConfig":{"tools":[{"toolSpec":{"name":"TestSpec","inputSchema":{"json":[]}}}]}}
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 00000000000001030000000000000000
request.headers.X-Amz-User-Agent was set to array(1) {
[0]=>
string(59) "aws-sdk-php/3.316.4 ua/2.0 OS/Darwin#23.5.0 lang/php#8.1.28"
}
request.headers.User-Agent was set to array(1) {
[0]=>
string(59) "aws-sdk-php/3.316.4 ua/2.0 OS/Darwin#23.5.0 lang/php#8.1.28"
}
-> 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 00000000000001030000000000000000 to 00000000000000ff0000000000000000
request.headers.aws-sdk-invocation-id was set to array(1) {
[0]=>
string(32) "cd0617c88ec577008c361985bdabaa4e"
}
-> Entering step sign, name 'retry'
-----------------------------------
request.instance changed from 00000000000000ff0000000000000000 to 00000000000001040000000000000000
request.headers.aws-sdk-retry was set to array(1) {
[0]=>
string(3) "0/0"
}
-> Entering step sign, name 'signer'
------------------------------------
request.instance changed from 00000000000001040000000000000000 to 00000000000000dd0000000000000000
request.headers.X-Amz-Date was set to array(1) {
[0]=>
string(16) "20240723T093614Z"
}
request.headers.Authorization was set to array(1) {
[0]=>
string(233) "AWS4-HMAC-SHA256 Credential=[KEY]/20240723/eu-west-2/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.eu-west-2.amazonaws.com:443 was resolved.
* IPv6: (none)
* IPv4: 13.40.249.205, 13.43.16.209, 35.176.152.80
* Trying 13.40.249.205:443...
* Connected to bedrock-runtime.eu-west-2.amazonaws.com (13.40.249.205) 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.eu-west-2.amazonaws.com
* start date: May 21 00:00:00 2024 GMT
* expire date: Jun 19 23:59:59 2025 GMT
* subjectAltName: host "bedrock-runtime.eu-west-2.amazonaws.com" matched cert's "bedrock-runtime.eu-west-2.amazonaws.com"
* issuer: C=US; O=Amazon; CN=Amazon RSA 2048 M03
* 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.eu-west-2.amazonaws.com
Content-Type: application/json
X-Amz-User-Agent: aws-sdk-php/3.316.4 ua/2.0 OS/Darwin#23.5.0 lang/php#8.1.28
aws-sdk-invocation-id: cd0617c88ec577008c361985bdabaa4e
aws-sdk-retry: 0/0
X-Amz-Date: 20240723T093614Z
User-Agent: aws-sdk-php/3.316.4 ua/2.0 OS/Darwin#23.5.0 lang/php#8.1.28 GuzzleHttp/7
Content-Length: 162
* upload completely sent off: 162 bytes
< HTTP/1.1 400 Bad Request
< Date: Tue, 23 Jul 2024 09:36:14 GMT
< Content-Type: application/json
< Content-Length: 148
< Connection: keep-alive
< x-amzn-RequestId: a33cbdc8-b32f-4dba-b8a7-079c279419ad
< x-amzn-ErrorType: ValidationException:http://internal.amazon.com/coral/com.amazon.bedrock/
<
* Connection #0 to host bedrock-runtime.eu-west-2.amazonaws.com left intact
<- Leaving step attempt, name 'ApiCallAttemptMonitoringMiddleware'
------------------------------------------------------------------
error was set to array(13) {
["instance"]=>
string(32) "00000000000001520000000000000000"
["class"]=>
string(52) "Aws\BedrockRuntime\Exception\BedrockRuntimeException"
["message"]=>
string(774) "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."}"
["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(13): Aws\AwsClient->__call('converse', Array)
#17 {main}"
["type"]=>
string(6) "client"
["code"]=>
string(19) "ValidationException"
["requestId"]=>
string(36) "a33cbdc8-b32f-4dba-b8a7-079c279419ad"
["statusCode"]=>
int(400)
["result"]=>
NULL
["request"]=>
array(6) {
["instance"]=>
string(32) "00000000000000dd0000000000000000"
["method"]=>
string(4) "POST"
["headers"]=>
array(9) {
["X-Amz-Security-Token"]=>
string(7) "[TOKEN]"
["Host"]=>
array(1) {
[0]=>
string(39) "bedrock-runtime.eu-west-2.amazonaws.com"
}
["Content-Type"]=>
array(1) {
[0]=>
string(16) "application/json"
}
["X-Amz-User-Agent"]=>
array(1) {
[0]=>
string(59) "aws-sdk-php/3.316.4 ua/2.0 OS/Darwin#23.5.0 lang/php#8.1.28"
}
["User-Agent"]=>
array(1) {
[0]=>
string(59) "aws-sdk-php/3.316.4 ua/2.0 OS/Darwin#23.5.0 lang/php#8.1.28"
}
["aws-sdk-invocation-id"]=>
array(1) {
[0]=>
string(32) "cd0617c88ec577008c361985bdabaa4e"
}
["aws-sdk-retry"]=>
array(1) {
[0]=>
string(3) "0/0"
}
["X-Amz-Date"]=>
array(1) {
[0]=>
string(16) "20240723T093614Z"
}
["Authorization"]=>
array(1) {
[0]=>
string(233) "AWS4-HMAC-SHA256 Credential=[KEY]/20240723/eu-west-2/bedrock/aws4_request, SignedHeaders=host;x-amz-date;x-amz-security-token;x-amz-user-agent, Signature=[SIGNATURE]
}
}
["body"]=>
string(162) "{"messages":[{"role":"user","content":[{"text":"Hi, how are you doing???"}]}],"toolConfig":{"tools":[{"toolSpec":{"name":"TestSpec","inputSchema":{"json":[]}}}]}}"
["scheme"]=>
string(5) "https"
["path"]=>
string(57) "/model/anthropic.claude-3-sonnet-20240229-v1%3A0/converse"
}
["response"]=>
array(4) {
["instance"]=>
string(32) "00000000000001070000000000000000"
["statusCode"]=>
int(400)
["headers"]=>
array(7) {
["X-Amz-Security-Token"]=>
string(7) "[TOKEN]"
["Date"]=>
array(1) {
[0]=>
string(29) "Tue, 23 Jul 2024 09:36:14 GMT"
}
["Content-Type"]=>
array(1) {
[0]=>
string(16) "application/json"
}
["Content-Length"]=>
array(1) {
[0]=>
string(3) "148"
}
["Connection"]=>
array(1) {
[0]=>
string(10) "keep-alive"
}
["x-amzn-RequestId"]=>
array(1) {
[0]=>
string(36) "a33cbdc8-b32f-4dba-b8a7-079c279419ad"
}
["x-amzn-ErrorType"]=>
array(1) {
[0]=>
string(72) "ValidationException:http://internal.amazon.com/coral/com.amazon.bedrock/"
}
}
["body"]=>
string(148) "{"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."}"
}
}
Inclusive step time: 0.11353015899658
<- Leaving step sign, name 'signer'
-----------------------------------
no changes
Inclusive step time: 0.11367201805115
<- Leaving step sign, name 'retry'
----------------------------------
no changes
Inclusive step time: 0.11636590957642
<- Leaving step sign, name 'invocation-id'
------------------------------------------
no changes
Inclusive step time: 0.1164219379425
<- Leaving step sign, name 'StreamRequestPayloadMiddleware'
-----------------------------------------------------------
no changes
Inclusive step time: 0.11646103858948
<- Leaving step build, name 'recursion-detection'
-------------------------------------------------
no changes
Inclusive step time: 0.11649203300476
<- Leaving step build, name 'request-compression'
-------------------------------------------------
no changes
Inclusive step time: 0.1165189743042
<- Leaving step build, name 'EndpointDiscoveryMiddleware'
---------------------------------------------------------
no changes
Inclusive step time: 0.11654591560364
<- Leaving step build, name 'endpoint_parameter'
------------------------------------------------
no changes
Inclusive step time: 0.11657214164734
<- Leaving step build, name ''
------------------------------
no changes
Inclusive step time: 0.11661696434021
<- Leaving step build, name 'ApiCallMonitoringMiddleware'
---------------------------------------------------------
no changes
Inclusive step time: 0.11666393280029
<- Leaving step build, name 'builder'
-------------------------------------
no changes
Inclusive step time: 0.11759090423584
<- Leaving step build, name 'endpoint-resolution'
-------------------------------------------------
no changes
Inclusive step time: 0.12050485610962
<- Leaving step build, name 'auth-selection'
--------------------------------------------
no changes
Inclusive step time: 0.12094521522522
<- Leaving step validate, name 'validation'
-------------------------------------------
no changes
Inclusive step time: 0.12100195884705
<- Leaving step init, name 'idempotency_auto_fill'
--------------------------------------------------
no changes
Inclusive step time: 0.12129616737366
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."}'
GuzzleHttp\Exception\ClientException: 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...)
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(13): Aws\AwsClient->__call('converse', Array)
#16 {main}
Next Aws\BedrockRuntime\Exception\BedrockRuntimeException: 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."} 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(13): Aws\AwsClient->__call('converse', Array)
#17 {main}
thrown in /Volumes/Sites/test/vendor/aws/aws-sdk-php/src/WrappedHttpHandler.php on line 196 |
@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? |
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 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
|
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
The text was updated successfully, but these errors were encountered: