Skip to main content

Notifications

Copilot Studio - General
Unanswered

Regex or alternative to extract number from generative answer

Posted on by 4

Hi,

I'm trying to chain together information from a custom copilot (using Copilot Studio) and hitting a wall with parsing out variables from a generative response. So far I've successfully created a topic that extracts vehicle properties from a SharePoint Excel file. The generative answer includes a 7 digit identifying number as part of a block of text. I've tried using parse value and set variable value nodes with a formula to extract that 7 digit number and save to a new variable for use in an API call. The Power Fx functions in the formula bar don't seem to support regex to extract this bit of information. Searching through the formula reference, I can't come up with any alternatives that would work.  Surely there must be a way to manipulate a string output for use in another action. What am I missing?

Thanks

  • YassineI Profile Picture
    YassineI 55 on at
    Re: Regex or alternative to extract number from generative answer

    Hey @SC1043

     

    Here is an example of an instant plugin that perform a REGEX used in a Power Automate context

    - Open this app 

    YassineI_1-1716026726432.png

     

    - Click on Create instant plugin.

    - Then you can add your input field / output field and your Power FX

    YassineI_0-1716026713304.png

     

    And this is how I call my plugin in a Power Automate flow. 

    YassineI_2-1716026807251.png

     

    If you pass to your flow the generated text and then you pass that text to you Dataverse action, the output should be the desired value (of course you need to adapt the power fx with your REGEX)

     

    I hope it helps, 

    Kr,

    Y.

  • SC1043 Profile Picture
    SC1043 4 on at
    Re: Regex or alternative to extract number from generative answer

    Thanks for the additional suggestions Yassinel. 

    I've tried modifying the instructions in the generative answer node to separate or demarcate the number variable I'm trying to capture, but it seems to be resistant to that guidance. I've done some initial poking around with the flows you've suggested. I appreciate there's more capability there, but so far I haven't been able to successfully call a function and return the output I'm looking for to copilot studio. I'll have to keep chipping away at it. 

    Thanks

  • YassineI Profile Picture
    YassineI 55 on at
    Re: Regex or alternative to extract number from generative answer

    @SC1043 

     

    I understand your situation, I see 3 alternative solutions:

     

    - You could adjust the prompt in your generative answer node to produce two values as the response. First would be the text you're presently generating, and then you could include a separator (like "||") followed by the 7 digits you need. Afterwards, you can use PowerFx to split this text using the separator, and then get the second item from the newly formed array.

     

    - You could also create a flow that employs a GPT model or AI Builder to perform data extraction.

     

    - Another option is to establish a flow with a Dataverse instant plug-in. This would perform data extraction using the Match function (What is Microsoft Dataverse Accelerator? (dynamics.com))

     

    Good luck ! I hope you reach your goals asap !

    kr, 

    Y.

  • SC1043 Profile Picture
    SC1043 4 on at
    Re: Regex or alternative to extract number from generative answer

    Thanks for the response. Match is in fact the first thing I tried, but it doesn't seem to be one of the functions available in Copilot Studio. My formula below generates this error: "'Match' is a recognized but not supported function."

    Match(Text(Topic.VehicleDetails),"/\d{7}/")
     
    I'm starting to think Copilot Studio has limited abilities in this regard. I'm not a Power tools user but, the Copilot function list appears to be just a small subset. 
  • YassineI Profile Picture
    YassineI 55 on at
    Re: Regex or alternative to extract number from generative answer

    Hey @SC1043 

     

    PowerFx is available when you set a variable in copilot studio.

    When you need to perform a REGEX in a PowerFx context you can take a look at this IsMatch, Match, and MatchAll functions - Power Platform | Microsoft Learn

     

    (Bonus: ChatGPT is really good to generate the right REGEX for you 😁)

     

    I hope it helps, 

    Kr, 

    Y.

     

Helpful resources

Quick Links

Welcome to the Power Platform…

We are thrilled to unveil the newly-launched Power Platform Communities!…

Getting Started…

Welcome to the Power Platform Community! We appreciate your visit…

Welcome to the new Power Platform Community!…

We are excited to announce our new Copilot Cookbook Gallery in the Community…

Leaderboard

#1
WarrenBelz Profile Picture

WarrenBelz 138,030

#2
RandyHayes Profile Picture

RandyHayes 76,308

#3
Pstork1 Profile Picture

Pstork1 63,085

Leaderboard