Robert Brown said sentences must be a matter for the courts, not politicians
Proposals for mandatory jail terms for those who carry knives could cost more than £80m a year in Scotland, figures obtained by the Lib Dems suggest.
The party claims an extra 1,345 people would be jailed under the proposals.
Labour want six-month terms for knife carriers, which the Lib Dems claim would cost £21m. It said Tory plans for two-year sentences would cost £83m.
Labour and the Conservatives said the number of knife carriers would be reduced if there were tough deterrents.
The Lib Dems based the figures on Scottish Prison Service (SPS) estimates on how much it costs annually to keep inmates in jail.
A parliamentary answer from Community Safety Minister Fergus Ewing indicated that an extra 1,345 convicts would be jailed for the offences of having in a public place an article with a blade or point, possession of an offensive weapon or restriction of offensive weapons.
The SPS estimated that prisoners cost about £31,106 to keep in jail annually.
Robert Brown, the party's justice spokesman, said: "Labour and Conservative proposals are pie in the sky. Scotland's jails are overcrowded as it is.
"If an extra 1,345 offenders were sent to prison, we'd need to build another Barlinnie just to house them all.
"All the evidence suggests most of them would come out of prison worse than they went in, and a more serious danger to the public."
Mr Muir's attacker had twice avoided jail after being caught with a knife
Labour has lodged amendments to the Criminal Justice and Licensing Bill at Holyrood, calling for the automatic six-month sentence.
It agreed to take forward a campaign by John Muir, whose son Damian, 34, was murdered in Greenock in 2007. His attacker had twice avoided prison after being caught carrying knives.
But Mr Brown said: "Mandatory sentences are unworkable, ineffective and completely unaffordable.
"Liberal Democrats think this money would be better spent keeping knives out of young people's hands and battling against gang culture.
"The appropriate sentence in individual cases must be a matter for the courts, not politicians."
However, Labour said the number of knife carriers would drop if there was a deterrent.
Its justice spokesman Richard Baker said: "Labour this week exposed the fact that 70% of knife criminals currently avoid jail.
"Only sending this tough message will deter knife criminals. The right approach will mean fewer criminals carrying knives and therefore fewer criminals would have to go to prison.
"However, this is also a question of principle. There were a record 57 knife murders in Scotland last year - does Robert Brown want to give me a figure what saving a life is worth?"
John Lamont, the Conservative community safety spokesman, said: "The Lib Dems have shown they care more about the criminal than the victims of crime."
He said the party had based its figures on "far more than knife carrying".
"A mandatory minimum sentence for carrying a knife would act as a massive deterrent and any amount of dodgy arithmetic from the Lib Dems won't alter that fact," he added.
"If they want to be soft on crime, let them proclaim it on every election leaflet."
When opposition parties made the call for mandatory sentences, the Scottish government said harsh penalties were already in place.
Justice Secretary Kenny MacAskill said: "We've seen jail terms for knife-carrying increase by a third, and I have made it clear that those who use a knife should expect to go to jail."