This is a re-occurring topic. Search the thread for "ao3 tags".
The short answer is that there's really no winning with AO3's tag structure as long as they allow authors to enter anything they like. They even have a special team of "tag wranglers" (with
documentation) to link authors' random tags to 'canonical' meanings.
And before you ask, no, there's currently no good way for FFF to use those canonical tags. Looking up all the tags on a story isn't feasible when so many have dozens or even hundreds of tags. Not until they start having a mode or page where you can see the 'canonical' tags for a story instead of/in addition to the author's tags anyway.
I will help you with specific replace_metadata issues; but as general problem, I consider it unsolvable in practical terms.