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());
}
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.
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.