Share feedback, ideas and get community help

Updated 4 months ago

Specifying `maxlength` on a Text Input block

At a glance

The community member has a Typebot with a Text Input block that collects text to be passed into an AI service. They want to enforce a maximum length on the input to cap the number of input tokens. The community members discuss potential solutions, such as using a Condition block for validation, and a workaround involving a Set Variable block to track the length of the input. However, there is no explicitly marked answer in the comments.

Useful resources
I have a typebot with a Text Input block that collects text that I later pass into an AI service. I'd like to enforce a max length on this input in order to cap the number of input tokens spent. I see that there's a short text input vs long text input distinction, but I haven't spotted a way to limit the maxlength on the short text input. Is there a way to limit this? Thank you!
B
a
8 comments
You should add a condition block right after the text input to enable any sort of validation.
The goal here is that it is compatible on platform where max-length attribute is not a thing like WhatsApp
But still I guess I could provide that option and validate it automatically for WhatsApp
Thanks! It looks like a Condition block can't operate on the length of text string, so I'm not sure that would work. I also tried using a Script block to truncate the text in the variable, but found that the System.Transcript still included the original user-inputted value (rather than what the Script block modified it to be), so that didn't quite work either.

The solution mentioned in the Github issue sounds good!
Oh thanks for mentioning the conflict with setVariable in Script and Transcript. Most likely a bug
Will take a look into this.
And indeed the workaround for now would be to add a Set variable block Answer length with content: {{Answer}}.length and then have a condition against this particular variable
Add a reply
Sign up and join the conversation on Discord