There are various mistakes in the smart filter code – for example you're checking the length of the keys array rather than the length of each key within. And you're not returning an error string if a key is wrong.
The basic structure of the code you need is this:
function filterstreamitem()
{
var item=getfilterstreamitem();
for (var k=0; k<item.keys.length; k++) {
var key=item.keys[k];
if ([some condition on key])
return 'Key '+key+' is invalid because ...';
}
}