AI component struggling to create a multi-select choice list

Thanks to Robert Petito’s Beastly video on AI components I’m able to create choice components easily. EXCEPT choice components that support multiple selections.

No matter how i prompt the AI - it wants to store the selected value as a boolean (true) if any item in the list is selected. I give it super specific details to store the selected value from the joinedlist that populates the choices - but to no avail. It always stores true.

the other weirdness is that the list will select every option as selected by clicking on any item. grrrr.

When i remove multi-select, the component operates fine in single selection mode. i have tried prompting the component to store the selected item values as a comma separted array into the target column which is a text field in my users table.

If there is some Glide voodoo that you-do to get around this - me and this app that i gotta provide to my local foodbank client will be very grateful.

cheers

Can you share how you have prompted it?

I would start straight to the point, like telling it to provide a dropdown, multiple choice component that stores values as comma-delimited string.

Then adjust as it goes on. I find prompting it super-specific in human language doesn’t help much, the only time I use a long prompt is when I generate stuff from outside LLMs (say Claude), and paste the result into Glide to give it a head start.

Otherwise I just start straight to the functionality and care about the looks later.

for single selection components i have success using

  • create a choice list displayed as radio buttons from the option field and write to order
    (this approach is ignored when the choices are multiple)

Here’s what I am trying (all are ignored) for the multiple choice

  • write selected option fields separated by commas to order
  • write clicked option field values to order

i have tried a zillion versions of the above and all are ignored.

if anybody is able to write multiple values using an AI component let me know.

thanks

Like @ThinhDinh mentioned, I tend to keep my prompts short and only ask for one thing at a time instead of creating wordy prompts with multiple requests.

I’ve also had decent luck being pretty vague in what I’m asking. Seems like it works better sometimes if you are less specific which seems to give the AI a little more freedom to figure it out on it’s own.

Are you specifying radio buttons for your multi select? By nature, radio buttons only allow one selection at a time, whereas checkboxes allow multiple. If you are trying to enforce radio buttons, it might be creating an internal conflict because multi select radio buttons are impossible in the same grouping.

Maybe try asking “overwrite bound column with a comma delimited list of selections”

1 Like

i can create single selection lists easily.

The issue is with multiple selection choice lists. It goes dark on me. Either it selects ALL the items in the list or it selects 1 at a time but is not able to write to the comma separated array to my text column.

Try this out.

2 Likes

yowza! Fascinating to see how you prompt it towards the functionality you need.

Very cool of you to do this. Will see how I can use this.

I will be creating a JSON structure to keep the count and the item together as well.

Thanks!

1 Like

In this case I did not create any data items before i started prompting the ai. I went straight to the prompt and it created the data items. That part always seems hard to get working correctly from the start.

Out of curiosity, how would you use this differently from a native multi-select choice component? Are you trying to execute actions as well when choices are made? I’m assuming so based on your other thread.

two follow ups.

Providing choice rows to the component:

my understanding is that AI components need strings so I have been creating joined lists of my items. I have a column for the name and a separate query for the counts. these create comma separated strings. e.g. item1, item2, item3 and 30,20,45 respectively.

I use these to populate my single selection radio choice lists. works great. I need to decrement the counts when items are selected that’s why I went with the AI component since I can update the count in real-time.

JSON Structure
I am not using a JSON structure for this yet as the JSON I currently get includes all the values of each column not just one item at a time because of the joined list limitation. e.g.

{
itemthing: “item1, item2, item3…”
value: “30, 20, 45, …”


}

it would be SO MUCH EASIER if the AI choice component could simply function like the native choice component…

A JSON object similar to what I shared (which I grabbed and modified from @ThinhDinh in your other thread) is just something that’s going to be understood by the code a whole lot better. It’s going to maintain the relationship between each item and it’s respective value a whole lot better than two joined lists which aren’t technically linked to each other item by item. Otherwise you would maybe have to instruct the AI to index each item in each joined list so that they correspond by index number. I don’t know. The AI component is finicky enough, but a well structured JSON object is going to help.

The JSON would be easy to create by building a JSON Object in the table that contains items and values. Then create a Relation and Lookup in the table that you intend to use that JSON. And finally create another JSON Object that packages all items from the lookup into one big JSON object.

I guess I’m not quite following on the decrement part. I mean I get that it could take that number, subtract something and then output it, but I’m not sure I follow in the whole scope of your flow. Based on your snippet of items and values you shared above, what would you expect for output when you select two items for example? What do you do with that output afterward? What if you unselect something in the choice?

1 Like

okay - i got this working. and I’m not sure how.

order is the text column I’m write to
combo is the joined list I’m reading rows of choices from

here’s the prompt order

  1. added the data above
  2. create a multiple choice list with options a,b, c
  3. allow multiple selections
  4. set max selections to 2
  5. read the choices from the combo field
  6. write the selected choices to order

The odd thing is I have fed this order into the component dozens of times but this time it magically worked. no idea but I’ll take the win

I guess I got lucky with the AI component aligning the two different lists. I sort the queries the same way for both the items and the counts but agree that the JSON structure is the way to go.

the basic flow is

  1. a choice list displays item 1 count x
  2. all the items in the list display their remaining counts as well
  3. when an item is clicked - the row is highlighted and the decremented count is displayed.
  4. if the item is deselected the count returns to its original pre-decremented value
  5. when the order is submitted, the decremented counts overwrite the original count so all users now see the new remaining count.

The reason I’m doing this is that there are multiple order takers for the foodbank that are providing items to clients. they need to be aware of the counts of remaining items as clients are served.

I add the relations and lookups from my users table to the allitems table and added the lookup json to the master order json.l. I think that’s what you’re suggesting.

I believe the next step is to use this JSON to as the source data for the choice lists.

I think the way you set this up will eventually lead to a race condition. What if 2 increment/decrement actions are executed at the same time from user devices? That would make your count not aligning correctly anymore.

Or is there no chance two people would click those at the same time?

good question. Yes there is a chance but what kind of time difference do you think would trigger a race condition? I imagine it will be around 1 minute between updates.

If two people click the same items within seconds, I would imagine there’s a problem.

here’s the sample json i have generated for the “protein” category that I need to use for the multiple choice list

{
“luProteinAllItems”: [
{
“productCombo”: “First protein 2 lb.”,
“displayCount”: 80
},
{
“productCombo”: “second protein 1 lb.”,
“displayCount”: 30
},
{
“productCombo”: “Pork Shoulder 2 lb”,
“displayCount”: 30
},
{
“productCombo”: “Hot Dogs 2 lb.”,
“displayCount”: 2
}
]
}

I’m attempting to use this json rather than the hardcoded example in your demo app - and the AI isn’t able to parse it with the prompts I’m attempting. ideas?

If you copy the component from my template and paste it into your template, it should be exactly the same. As for the JSON, the easiest would be to replace your variable names with the ones I used (data, item, value). That way you don’t have to reinvent the component again to use JSON with different variable names like in your sample. The code is looking for this specific variable names in the JSON object.

If you still wanted to use yours Justin structure, you could try pasting the JSON into the prompt and tell it that it is your new json structure. Not sure if that will work right off the bat or not. The AI is stubborn sometimes.

The only thing left would be to instruct the component to decrement the number. Still curious how to plan to to update rows with the updated counts though. If you are updating multiple rows, you would have to involve the API and building a JSON payload to upload multiple. You would also need the RowID for each item. I don’t know…it just feels like a complicated approach that you are taking, and I’m not sure how you plan for it to all work once the form is submitted.

On a simpler level, you could just use the native multi select choice component, display the item names, but write the RowID. When you submit your form you would end up with a comma delimited list of RowID’s. Then you could create a relation from the the items table to the order table, create a Rollup to count the number of matches, and subtract the Rollup count from the item count. It doesn’t permanently adjust the item quantity, but the math result would be correct as long as you never delete any orders. It’s not the best method, but it’s simpler.

Ultimately some kind of workflow would be best. A choice component the gives you a comma delimited list of selected row IDs or a JSON object with an array of RowID’s and quanties, an action that calls a webhhook, and a webhook workflow that loops through the JSON or comma delimited RowIDs, and decrements from each item row as the loop spins through each row id.

None of this is something I’ve attempted myself, so I didn’t have a good tutorial or best practice. On the other hand, maybe you have a plan worked out, that I’m not aware of, when the order is submitted.

Sorry, I’m throwing a lot out there, but I want to make sure the the process it fully thought out after the submit button is pressed. Reading through your posts again, I guess you do mention allowing only 2 selections. This does make it easier. I think I would still go for the native choice component. Write or the row IDs for the selections. Split them into an array. Create 2 single value columns to get each individual row id. Create 2 single relations to link to each respective item. Then set up a workflow that will decrement each item by 1 the through each relation. Maybe that would be best…

1 Like

UPDATE: re: Trickery
I believe that attempting to write a value to an empty relation is never going to work. would love to get that confirmed.

A workaround I’m considering is to use a dummy row in my items table and refer to that empty item when doing the count decrement action.

Hope this works.

no need to ever be sorry for helping out.
I’ve got the app working great with one big gotcha.

My app uses the original count value for items and a decremented value. I display the decremented value for selected items. this is cool in that it instantly updates the display count without updating the actual item count. users can then select/deselect until they are happy with the selections.

I have 6 categories not 2, so there’s a lot of columns.

The gotcha come when I update the order using an action. I write the display count over the top of the original count values for the items that were selected using relations. So if category A item 1 was selected and the count was 5 it gets overwritten with 4. Everybody’s happy until I get to a category that is empty…

Since I am using a relation to update the item count when there is no selected item/relation, Glide is attempting to write a null value from the loookup over the original count value and it halts the workflow. grrrrrr.

I changed the count field from a number to a text column - the decrement math still works but this also freezes the workflow due to the null value thang.

I would have to build an insane if-then-else branch thing to try to account for all the combinations of valued / empty choices. dead-end.

If there was a way to run the updates only for those items where a relation exists and not for the empty ones I think I could avoid the halting workflow action.

There is likely some Glide trickery to get around this sitch… hmmmm

It’s a lot to digest in the thread here, but it looks to me that you should trigger a webhook workflow on a button click, loop through items and only use set columns where the relation is not empty.