Hello David,
First of all your checking for a to-tag is correct. In-dialog requests should have a to-tag, and therefore the block you pasted here won't execute at all for those.
If you're worrying about provisional (1xx) replies sent from the UAS for the initial INVITE, then indeed some of them might also not have a to-tag set. However, if the code block you pasted is in the request_route() "main" route, then it won't be executed anyway. For responses to be specially processed via the configuration script, you either have to have a reply_route() set, or an onreply_route() set if you're doing stateful processing with the tm module.