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?

TT.
  • 15,774
  • 6
  • 47
  • 88
dinod7
  • 51
  • 2

4 Answers4

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.

tishma
  • 1,855
  • 1
  • 21
  • 43
  • 1
    This is the correct answer. Bots, Intents, and Slot types can only have letters and non-consecutive underscores. – eczajk Jun 29 '19 at 02:52
3

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

Dave Kerr
  • 5,117
  • 2
  • 29
  • 31
  • That was the problem. Thank you so much!! – dinod7 Jul 13 '17 at 13:21
  • 1
    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! – Dave Kerr Jul 14 '17 at 03:22
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"
    }
]

};

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"]  
                              )
Stefan
  • 23
  • 3