I am trying to parse the SQL CodeBlock alone from the AI Agent output using the code node with the script below, but unable to parse the SQL output
// Access the input data
const inputData = $input.all();
// Function to extract code blocks from text
function extractCodeBlocks(text) {
// Regular expression to match code blocks
const codeBlockRegex = /sql\n([\s\S]*?)
/g;
// Array to store extracted code blocks
const codeBlocks = ;
// Extract code blocks
let match;
while ((match = codeBlockRegex.exec(text)) !== null) {
codeBlocks.push(match[1].trim());
}
return codeBlocks;
}
Snapshot of the workflow as below
Code Block output
Can you please help me build this workflow which integrates with SnowFlake and Dbt
thanks,
Sree
Hi,
There are many online regex explorer which you can use to help build and test your regex expressions. It’s beyond the scope of this forum.
reg,
J.
I am using regex but it wouldn’t output it, here is another example
const inputData = $input.all(); // Assuming AI output is passed to this node
const fltData = inputData.filter(/sql[\s\S]*?
/)
return fltData;
Hi,
If you didn’t get the right output, then most likely your input data / instructions were not clear and the AI agent just did a best-effort. If you want exact output you need to improve your prompting and/or provide example output for given inputs etc. Currently the AI output is given a response that is totally unrelated to what you require.
From your screenshot I cannot comment anything further.
reg,
j.
The AI Agent output is correct it is a combination of Explaination (simple english test) and the sql codeblock (CREATE TABLE STATEMENTS multiple) and the summary(in plain english). All I want is the CREATE statements, I want to to leave the rest so that I can execute in a db. I used .replace but it says it is not supported, I used filter as well but of no effect.
Hi,
How can anybody troubleshoot that of 2 screenshots which don’t show all the Info.
Reg,
J.
Hi @Sreekanth_Yedla
I think you need to integrate Structured Output Parser
into your AI Agent
and define a Schema that suits your needs…