Shortcut - “Use Model” error handling?

I have a series of shortcuts that I’ve written that use the “Use Model” action to do various things. For example, I have a shortcut “Clipboard Markdown to Notes” that takes the content of the clipboard, creates a new note in Notes, converts the markdown content to rich text, adds it to the note etc.

One key step is to analyze the markdown content with “Use Model” and generate a short descriptive title for the note.

I use the on-device model for this, but sometimes the content and prompt exceed the context window size and the action fails with an error message to that effect.

In that case, I’d like to either repeat the action using the Cloud model, or, if the error was a refusal, to prompt the user to enter a title to use.

I‘ve tried using an IF based on whether the response had any text in it, but that didn’t work. No matter what I’ve tried, I can’t seem to find a way to catch the error from Use Model, determine what the error was, and take appropriate action.

Is there a way to do this?

(And by the way, a huge ”thank you” to whoever had the idea of making AppIntents visible in Shortcuts and adding the Use Model action — has made a huge difference already, and it lets us see what Siri will be able to use as well.)

Assuming you are using Apple's Foundation Models framework, you should be able to catch an error when exceeding the context window size or hitting the other errors. How to do so is detailed in Handle the exceeding context window size error elegantly and also this post.

Best,
——
Ziqiao Chen
 Worldwide Developer Relations.

Hi,

Thank you for your response, however, I’m not using it from a Swift app - I’m using the “Use Model” Action in the Shortcuts app, since it has access to the server model as well as the on-device model, and, it also has the ability to utilize the AppIntents provided by other apps on the device which also appear as Actions.

Oh, I thought you were writing your own shortcuts that use the models, which completely missed your point. Sorry for that.

The answer then is that there is currently no way to detect an error from an action. I checked with the Shortcuts folks and they suggested that you file a feedback report with your use case to request the support of try-catch in Shortcuts – If you do so, please share your report ID here.

Best,
——
Ziqiao Chen
 Worldwide Developer Relations.

Shortcut - “Use Model” error handling?
 
 
Q