Sword fighters are usually barely armoured and fight without shields to retain their mobility. Thus they can circulate around the immobile Phalanx formation and attack from the flanks.
During battle, Swordsmen deploy to the flanks, unless they are needed to fill the front battle line.
↑Test performed in v0.3.4 as follows: Sent 5 swordsmen against level 6 barbarian villate (63% hit points in round 1. 51% hit points in round 2 with 2 dead. All 5 dead in round 3.) Sent 5 swordsmen accompanied by 30 doctors (63% health points in round 1. Still 63% at the end of round 2. Still 63% at the end of round 3.)