Proper error handling for invalid key names