It is not unfair. It is to my knowledge standard practice in a civil suit.
Why should someone who has been sued and wins the case have to bear all his own legal costs?
After the verdict is in this is one of the pleadings before the court and the court makes a ruling. The winner does not get all his legal bill paid. There has to be some sober second thought on the party suing someone ridiculously.
In Canada (all I know) it is referred to as "party and party costs" which are costs awarded based on a tariff set by the court for that proceeding.
{Now in the US in the criminal courts are going after the criminals in some cases where the criminal lied and as a result the police etc incurred significant costs. }
In Canada in civil cases they do this award either party and party or the more costly solicitor and client costs:
Canadian courts follow the British practice of awarding costs at the conclusion of each
proceeding, whether that be a motion, application, trial, or appeal. The basic costs principle is that the successful party is entitled to compensation from the unsuccessful party for a portion or for all of its costs in a proceeding. That compensation may be partial (“party and party costs”, typically between 40% and 60% of actual costs) or substantially complete (“solicitor and client costs”, typically between 80% and 100% of actual costs). The quantum of costs is lower in the Federal Court.
I am sure the US does the same.