Amazon Lex Error: An error occurred (BadRequestException) when calling the PutIntent operation: RelativeId does not match Lex ARN format
Asked Answered
T

4

5

I'm trying to build a chatbot using Amazon's boto3 library. Right now, I am trying to create an intent using the put_intent function. My code is as follows:

intent = lexClient.put_intent(name = 'test',                                 
                              sampleUtterances = ["Who is messi?"]  
                              )

When I try running this, I get the following exception:

botocore.errorfactory.BadRequestException: An error occurred (BadRequestException) when calling the PutIntent operation: RelativeId does not match Lex ARN format: intent:test2:$LATEST

Can anyone tell me what I'm doing wrong?

Tumbledown answered 11/7, 2017 at 15:51 Comment(0)
P
7

I got the same error when trying to have a digit in intent name field. Realized that was not allowed when trying to do the same from AWS console.

Error handling could really be more specific.

Prostomium answered 21/7, 2017 at 22:34 Comment(1)
This is the correct answer. Bots, Intents, and Slot types can only have letters and non-consecutive underscores.Megalomania
O
3

Try taking the question mark out of the utterance, that has caused me issues in the past!

Osmic answered 13/7, 2017 at 10:50 Comment(2)
That was the problem. Thank you so much!!Tumbledown
No worries! Would you mind marking the answer as correct? It does seem a bit bizarre that the character which breaks utterances is the question mark character!Osmic
M
0

You need to run GetSlotType. That will return current checksum for that slot. Put that checksum in your PutSlotType checksum. Big bang boom.

https://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/LexModelBuildingService.html#getSlotType-property

var params = { name: "AppointmentTypeValue", checksum:'54c6ab5f-fe30-483a-a364-b76e32f6f05d',

description: "Type of dentist appointment to schedule'",
enumerationValues: [
    {
        value: "cleaning"
    },
    {
        value: "whitening"
    },
    {
        value: "root canal"
    },
    {
        value:"punch my face"
    }
]

};

Middlebrooks answered 13/5, 2020 at 14:26 Comment(0)
S
0

For the put_intent function I faced similar issues. At least the following 3 are worth mentioning.

  1. Sample Utterances

There are requirements for the sample utterances:

An utterance can consist only of Unicode characters, spaces, and valid punctuation marks. Valid punctuation marks are: periods for abbreviations, underscores, apostrophes, and hyphens. If there is a slot placeholder in your utterance, ensure that it's in the {slotName} format and has spaces at both ends.

It seems like there is no error raised when calling the put_intent function with the following code.

intent = lexClient.put_intent(name = 'test',                                 
                              sampleUtterances = ["Who is messi"]  
                              )

However, if you try to add it to your bot and start building the bot it will fail.

To fix it remove the question mark at the end of you sampleUtterance.

intent = lexClient.put_intent(name = 'test',                                 
                              sampleUtterances = ["Who is messi?"]  
                              )
  1. Prior intent version

If your intent already exists you need to add the checksum to your function call. To get the checksum of your intent you can use the get_intent function.

For example docs:

response = client.get_intent(
    name='test',
    version='$LATEST'
)
found_checksum = response.get('checksum')

After that you can put a new version of the intent:

intent = lexClient.put_intent(name = 'test',                                 
                              sampleUtterances = ["Who is messi"],
                              checksum = found_checksum
                              )
  1. Intent Name (correct in your case, just adding this for reference)

It seems like the name can only contain letters, underscores, and should be <=100 in length. Haven't found anything in the docs. This is just trial and error. Calling put_intent with the following:

intent = lexClient.put_intent(name = 'test_1',                                 
                              sampleUtterances = ["Who is messi"]  
                              )

Results in the following error:

BadRequestException: An error occurred (BadRequestException) when calling the PutIntent operation: RelativeId does not match Lex ARN format: intent:test_1:$LATEST

To fix the name you can replace it to:

intent = lexClient.put_intent(name = 'test',                                 
                              sampleUtterances = ["Who is messi"]  
                              )
Step answered 19/5, 2022 at 8:3 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.