Francis McLean and Valene Brown used the sword in a bid to steal almost £17,000 from Knightsridge Post Office in Livingston in May this year.
But they dropped around £15,000 of the cash after ‘brave’ shop assistant Aiden Saeed Gilani managed to wrestle the weapon away from the duo.
At the High Court in Edinburgh today McLean, of Erskine Way, was jailed for five years and three months.
The 50-year-old will serve a further two years on licence once he is released.
His accomplice Brown, 21, of Glen Crescent, was sentenced to three years in prison.
Sentencing the pair at the High Court in Edinburgh, Lord Andrew Hardie said Mr Gilani, who is the son of the office’s postmaster, bravely tackled the pair despite the fact McLean was “brandishing a sword with a 20 inch blade”.
“He managed to cause you to drop some of the money and was able to gain control of the weapon. Clearly his actions were extremely brave but could have resulted in serious consequences.
“The end result was you seemed to get away with just over £2,000, the balance of £15,000 or so being dropped in the shop,” added the judge.
The court heard that McLean brandished the weapon from his sleeve and then told Mr Gilani to lie down.
But after Mr Gilani wrestled the weapon from the pair he used the sword to chase the two out of the shop.
McLean and Brown fled on their bikes after the incident but their DNA was discovered on items left at the scene, the court heard.
Lord Hardie said McLean had previous convictions for drugs, dishonesty and a weapon charge, and said the post office robbery was committed while he was on bail.
The judge said: “I am satisfied that the public will not be adequately protected unless an extended sentence is imposed.”
He said to Brown was in a different position to McLean, as she was much younger and was a first offender.
Defence counsel Victoria Young said Brown did not use the sword herself, but had gone to the shop intending to hold the door open for McLean to distract the shopkeeper.
She added: “Brown did not take part in any actual violence, but she nevertheless played a role in the commission of the offence.”
Solicitor advocate Ian Bryce, said McLean’s crime was a ‘hapless’ one.
However, McClean had shown a degree of empathy and understanding for what the victim and his family had gone through.
But, he added: “The fact that the whole matter was caught on CCTV meant the chances of this robbery going ahead without the police arriving at his door were remote.”
At the High Court in Glasgow last month Brown and McLean pleaded guilty to assault and robbery.