Natural Language Message Validation with Logic Apps and ChatGPT

In one of my previous documents, I spoke about how to configure ChatGPT to be used with Azure Logic Apps. At that time, my team and I decided to create that blog post just for fun, but we didn´t yet have in mind a good idea of how to use it in a real-case integration scenario or to help build integration projects.

During a break at INTEGRATE 2023 conference, Mike Stephenson show me an idea that he had while listening to one of the talks about putting ChatGPT to do transformation using natural language, thereby replacing the maps. Needless to say, it was a fascinating and fun conversation. You can see his blog post here:

This put me thinking about where else we could apply ChatGPT in use to help develop, implement, or process our integration needs. Despite having a few ideas, one quickly stood out, and that somehow follows Mike’s idea: Messages Validation! In other words, have a Logic App which is processing some data, and then we use ChatGPT to validate the data for us by describing the schema validation in natural language text.

So I ended up creating this small sample scenario where we have the following JSON Message:

    "Company": "SP", 
    "Operation": "Insert", 
    "Request": { 
        "OrderID": 2, 
        "ClientName": "Sandro Pereira", 
        "ShippingAddress": "Pedroso, Portugal", 
        "TaxId": 111222111, 
        "ProductName": "Chocollate Bar", 
        "Quantity": 1 

And we want to validate the incoming message if it is valid or not based on the following rules:

  • The OrderID must exist and be an Integer. 
  • The ClientName can not be empty or null.
  • The Quantity must exist, and it is an Integer. 
  • The value of the Company field can only be “SP” or “LZ”.
  • The Operation field must exist. 

Of course, this task can be made by creating a JSON schema with all the rules and then validating the message against the schema. However, some of these rules are not natively supported by Logic Apps like the use of regular expressions or patterns.

But the main idea here on this post is to provide a simplified way to do this task and use natural language to replace the Schemas.

You can watch my coworker Luís Rigueira describing all the process in this video:

So how do we achieve this? 

First, as you already know, you should create a Logic App. It can be Consumption or Standard. We will be using Consumption, and then you should give it a proper name because starting using proper names from the day one rule never gets old! 

And then create a Logic App that has the following structure:

  • When a HTTP request is received trigger.
  • A Compose action.
  • An HTTP action.
  • And finally, a Response action.

Leave the When a HTTP request is received trigger as his. And on the Compose action, add the following configurations with all the actions to apply the validation of the message:

Check if the Json Input is valid or invalid by these rules:

The OrderID must exist and be an Integer
The client name can not be empty or null
The Quantity must exist and it is an Integer
Company can only be "SP" or "LZ"
Operation must exist

If it is valid return a message saying "body is valid"
If it is invalid return a message saying the "body is invalid" and explain why.

Json input: @{triggerBody()}

As the JSON input, we dynamically select the Body property from the Trigger, which contains the JSON we send via Postman.

Next, on the HTTP call, we need to perform the call to the ChatGPT API to perform or try to perform the JSON message validation. To do that, we need to specify the following body:

  "model": "gpt-3.5-turbo",
  "messages": [
          "role": "user",
           "content": "@{outputs('Compose_-_Instructions_to_be_followed')}",

If you want to know or understand a little bit about this – How to call ChatGPT from a Logic App – see my previous blog post: Using Logic Apps to interact with ChatGPT.

Finally, we need to configure the Response action to use the following expression in the response:


This way, we only send the message content as a response. Now if you test your logic app with Postman, this should be the result:

If the rules we added to the Compose action are met, we will get the following response:

  • The body will be valid.

Otherwise, the body is invalid, and ChatGPT gives the reason why.

Of course, I think at this stage maybe AI is still not a reliable option to be used in data transformation or data validation, but it shows potential.

Once again, thank my team member Luis Rigueira for helping me with this always crazy scenarios.

Hope you find this helpful! So, if you liked the content or found it helpful and want to help me write more content, you can buy (or help buy) my son a Star Wars Lego! 

Author: Sandro Pereira

Sandro Pereira lives in Portugal and works as a consultant at DevScope. In the past years, he has been working on implementing Integration scenarios both on-premises and cloud for various clients, each with different scenarios from a technical point of view, size, and criticality, using Microsoft Azure, Microsoft BizTalk Server and different technologies like AS2, EDI, RosettaNet, SAP, TIBCO etc. He is a regular blogger, international speaker, and technical reviewer of several BizTalk books all focused on Integration. He is also the author of the book “BizTalk Mapping Patterns & Best Practices”. He has been awarded MVP since 2011 for his contributions to the integration community.

Leave a Reply

Your email address will not be published. Required fields are marked *


Back to Top