Configure AI node
Leveraging an LLM model within a workflow is useful for classification or summarization actions. Cargo's AI integrations are built to allow the user to constrain the output format of the AI response to fit the needs of the data flow.
This guide will show us how to configure an instruct node. First, we will execute an AI prompt on scraped website data. Then we will ensure the instruct node returns a structured response that we can easily use in the rest of the workflow.
Used Features:
Before you begin
We will run the AI login on the results of a web scrape action. You need to ensure the "Firecrawl" connector is created and add a Firecrawl scrape node to your workflow.
Add an instruct node
Click on the "add node" icon and find the instruct node that will allow us to call the OpenAI API to provide a summarization of scraped website content. In our example, we want to get information about a company's value proposition based on its website.
Link the newly added node with the previous scrape node.
In order to get the industry information, we will use the "system prompt" option of the instruct node to give general instructions to the AI model. System prompt or message is a set of overarching instructions that define how the AI should behave across all interactions. In our case we can set it to the following value:
Analyze the content of a website provided as a text and output summarization of basic company information.
Then we will provide the actual website content in the main "prompt" field using a simple expression:
{{nodes.firecrawl_scrape.content}}
NOTE: Firecrawl returns the scraped page content in a few different formats, learn more in Firecrawl Connector documentation
While configuring the node we should consider how to use its output in the next steps of the workflow.
We would like to get a response as a JSON object with two parameters:
- company_name
- industry
To do that we will set a "response format" to "JSON schema" and paste the following content:
{
"type": "object",
"additionalProperties": false,
"required": [
"company_name",
"industry"
],
"properties": {
"company_name": {
"type": "string"
},
"industry": {
"type": "string"
}
}
}
Setting the JSON schema is a powerful tool, but it can also be an overkill for simple use cases.
For the basic usage, it is enough to control which properties are defined.
Each property needs to be specifically listed in the required
section of the snippet as well as inside the properties
section.
In the second case they just need one nested parameter type
that controls the format of the property value.
Run the instruct node
Once both prompts and "response format" are set we can run the instruct node and verify if the answer is in the expected format.
Click the "play" icon in the top right of the node pane and once it's done inspect the "answer" object in the "out" tab to see the expected outcome:
{
"answer": {
"company_name": "Cargo",
"industry": "Revenue Operations and Sales Automation"
}
}
Finish line
In this guide, you have learnt how to use the powerful instruct node to perform summarization tasks on website content in a predictable way. Using the "response format" feature with JSON schema allows us to ensure the results of AI operation precisely match our requirements and makes it easy to use in other nodes of the workflow.