Clean Form Inputs in n8n Before Sending Data to AIClean Form Inputs in n8n Before Sending Data to AI
The network for creativity
Join 1.25M professional creatives like you
Connect with clients, get discovered, and run your business 100% commission-free
Creatives on Contra have earned over $150M and we are just getting started
Most bad AI answers in a workflow start with messy input. Twelve lines of JavaScript fix a lot of it.
• The Code node runs once for all items.
• $input.all() reads every item from the form.
• Fields are trimmed, the email lower-cased, empty rows dropped.
• The clean items go on to the AI step.
What's the messiest field in your forms?
Follow for more videos: instagram.com/sellwrightstudio · youtube.com/@sellwrightstudio
Albert's avatar
Phone numbers. The same number arrives as (704) 555-0123, 704.555.0123 and +1 704 555 0123. Parsing with a phone library such as Google's libphonenumber, with a default country, and storing E.164 (+17045550123) makes all three one value, and entries like "mobile" fail to parse instead of slipping through.
Raja's avatar
Phone numbers are the worst one, agreed. Storing E.164 is the right target, and having junk like "mobile" fail loudly is better than it reaching the AI step. A Code node can't load libphonenumber on n8n Cloud, so there I'd send failed parses down a separate branch for a quick manual check.
Back to feed
The network for creativity
Join 1.25M professional creatives like you
Connect with clients, get discovered, and run your business 100% commission-free
Creatives on Contra have earned over $150M and we are just getting started