How about a production called something like makeUnionsUnknown(Set) that calls makeUnknown() for every fromUnion() tag found among the modifiers? Then we can do something like:

rule write-specific() => makeUnionsUnknown() ~> writeBytes()