toa: add flag() function to catch KeyErrors