I am building Data Analytics RAG Agent. To process structured and unstructured data to store in Supabase database I built this Workflow. I am facing an error on Column Validation Code Node, it is getting inpurt from Summarize Node but it is not processing the data and don’t even give any error. Can someone help me find the issue? Following is code which I am using in Column Validation Node:
function ($node, items) {
console.log(‘Incoming items:’, JSON.stringify(items, null, 2));
// Base column mapping - common variations
const baseColumnMapping = {
// Employee ID variations
'EMPLOYEE_CODE': 'employee_code',
'EMP CODE': 'employee_code',
'EMPLOYEE ID': 'employee_code',
'EMP ID': 'employee_code',
'ID': 'employee_code',
// Name variations
'EMPLOYEE_NAME': 'employee_name',
'EMP NAME': 'employee_name',
'NAME': 'employee_name',
'FULL NAME': 'employee_name',
// Department variations
'DEPARTMENT': 'department',
'DEPT': 'department',
'DEPT NAME': 'department',
'DEPARTMENT NAME': 'department',
// Email variations
'EMAIL': 'email',
'EMAIL ID': 'email',
'E-MAIL': 'email',
'MAIL': 'email'
};
try {
// Get data from input
const rawData = items[0]?.json?.data;
if (!rawData || !Array.isArray(rawData)) {
console.log('Invalid input data structure:', rawData);
throw new Error('Invalid input data structure');
}
console.log('Processing data rows:', rawData.length);
// Get all unique columns from the data
const firstRow = rawData[0];
const inputColumns = Object.keys(firstRow);
console.log('Detected columns:', inputColumns);
// Create dynamic mapping for unknown columns
const dynamicMapping = {};
inputColumns.forEach(column => {
const normalizedKey = column.toUpperCase().trim();
// If it's in base mapping, use that
if (baseColumnMapping[normalizedKey]) {
dynamicMapping[normalizedKey] = baseColumnMapping[normalizedKey];
} else {
// Create standardized name for new column
const standardizedName = column.toLowerCase()
.replace(/\s+/g, '_') // Replace spaces with underscore
.replace(/[^a-z0-9_]/g, '') // Remove special characters
.replace(/_+/g, '_'); // Replace multiple underscores
dynamicMapping[normalizedKey] = standardizedName;
}
});
console.log('Generated column mapping:', dynamicMapping);
// Map each row with dynamic mapping
const mappedRows = rawData.map(row => {
const mappedRow = {};
Object.entries(row).forEach(([key, value]) => {
const normalizedKey = key.toUpperCase().trim();
const mappedKey = dynamicMapping[normalizedKey] || key.toLowerCase();
// Handle empty or null values
mappedRow[mappedKey] = value === '' ? null : value;
});
return mappedRow;
});
console.log('Successfully mapped rows:', mappedRows.length);
// Return processed data with mapping information
return [{
json: {
success: true,
data: mappedRows,
column_mapping: dynamicMapping,
original_columns: inputColumns,
mapped_columns: Object.values(dynamicMapping)
}
}];
} catch (error) {
console.error('Error in column validation:', error);
return [{
json: {
success: false,
error: error.message,
input_received: JSON.stringify(items)
}
}];
}
}