In new beta you added filter_slot_count check so it should no longer cause out of range exception in get_filter.
Though not sure about
local filtered_slot = copy_event.filtered_slots[i]
Is filtered_slots always initialized with size 5? In Lua does indexing out of bounds causes error or just returns nil like in other languages (talking about you, javascript)?
My opinion you did not ask for: You should not loop hardcoded amount of times. For filtered inserter with only one slot you make 4 extra unnecessary loops (with a performance impact of whopping 0ms!!! Oh my god!!! /s). Loop from 1 to max(source.filter_slot_count, destination.filter_slot_count). You do not control all aspects of inserters so there might be a 10 slot filter inserter in the wild.