Python string splitting fails in Zapier automation

I’m trying to use Zapier to connect some applications together. I have a string called order_code that contains 6 different parts separated by underscores. An example would be pr123_x456_29.75_3_ABC_2023-08-15.

Here’s what I’m attempting:

parts = input_data['order_code'].split("_")

result = [{
    'prefix': parts[0],
    'order_num': parts[1], 
    'amount': parts[2],
    'quantity': parts[3],
    'seller': parts[4],
    'order_date': parts[5]
}]

I also attempted this approach:

prefix, order_num, amount, qty, seller, order_date = input_data['order_code'].split("_")

result = [{
    'prefix': prefix,
    'order_num': order_num,
    'amount': amount, 
    'qty': qty,
    'seller': seller,
    'order_date': order_date
}]

The problem is that Zapier gives me a generic error message that doesn’t help at all. It just says something like “Your code encountered an error” without any details.

I’ve tested this Python code outside of Zapier and it works fine. Has anyone run into similar issues with string operations in Zapier? Any suggestions would be great.

EDIT: Found the issue! The test data was showing correctly in the interface, but the actual input_data was empty during execution. The split function was working perfectly.

I hit this exact same issue with CSV imports through Zapier webhooks. Turns out it wasn’t my Python code - the source system was sending inconsistent data. Extra spaces and weird characters kept sneaking into strings, making the split act up. What fixed it was cleaning the data first: order_code = input_data['order_code'].strip().replace(' ', '') before doing anything else. Also found out some webhook sources wrap data in extra quotes or have encoding problems that don’t show up in Zapier’s test interface. Now I always validate that I’ve got exactly 6 parts after splitting before moving forward. The annoying thing? Zapier’s sandbox handles data totally different than production.

This is exactly why I ditched Zapier’s code steps completely. The debugging is awful - you’re basically flying blind when data doesn’t match what you expect.

Same thing happened to me with order data from our e-commerce system. Worked fine in testing, then randomly failed in production because of empty fields or format changes.

I switched to Latenode and it solved everything. You can build the string splitting workflow visually, and when it breaks, you actually see what went wrong. Plus you get proper error handling without writing try/catch blocks.

For your case, you’d create a scenario that takes the order_code, splits on underscores, then maps each part to the right field. You can test with real data and see exactly what each step produces.

No more guessing what input_data contains or dealing with Zapier’s useless error messages.

Glad you figured it out! This is one of the most common Zapier gotchas with code steps. The test interface is misleading - it shows sample data that doesn’t match what actually gets passed during live runs. I’ve been burned by this so many times where the mapping looked perfect in the editor, but the actual webhook was sending null values or completely different data structures. Now I always add logging at the start of my code steps to dump the raw input_data, then check task history to see what’s really coming through. Also watch out for subtle field name differences between test and live data, especially with webhooks from different systems. The split method works fine in Zapier’s Python environment, so it’s almost always a data issue when string operations break.

yeah, zapier’s error msgs r super frustrating. i suggest wrap your split in try/except and log the input. helped me a lot when i got unexpected data. good luck!