Lord Uist made the comment during the sentencing of Denis Duffy, 31, who robbed a Chinese restaurant on December 29, last year in Cumbernauld, North Lanarkshire.
The judge spoke moments after hearing how Duffy, who has 14 previous convictions, held a knife to Rory Chan, punched him and tried to rob him of a cash register.
A report which had been prepared for the High Court in Edinburgh on Duffy's character recommended that he be given a non-custodial sentence. Instead, Lord Uist jailed Duffy, a prisoner of HMP Addiewell, in West Lothian, for four years and eight months. He was also placed on supervision for four years following his release from prison.
Lord Uist added: "In light of your criminal record and the circumstances of the crime for which you now appear in this court, I am driven to the conclusion that the social worker who assessed you as presenting with a minimum level of criminogenic risks and as suitable for a community based disposal had taken leave of her senses when she made those assessments.
"I have no hesitation in coming to the view that you present a clear danger to the safety of the public."