implement safe query decoding