The Princess Royal unveiled a plaque to commemorate a new service at a HMP New Hall.
Staff lined the roads to get a glimpse of Princess Anne during her visit to the women’s prison, in Flockton.
She was given a private tour of the grounds and introduced to around 100 workers at The Chapel.
Princess Anne, drinking a cup of coffee, spent half an hour chatting with the staff.
One prison officer said Princess Anne was “very knowledgeable” and a “pleasure to talk with”.
Another worker said: “She was absolutely brilliant and took a real interest in what we are doing.”
Princess Anne unveiled the plaque to mark The Rivendell Service, launched in October last year.
The service, commissioned by NHS England, provides therapeutic services to females offenders with personality disorders.
Princess Anne was also asked if she would present a Butler Trust Certificate to prison officer Jeanette Gagg.
She was nominated by her peers for her role as an equality officer, a post she took up in 2008.
Mrs Gagg said: “We had a brief chat and she knew all about the work we have been doing.
“I was told that someone special would be coming in but to receive it from her was the icing on the cake.”
Mrs Gagg has been working for seven years to help improve equality in prison among and staff and inmates.
She said: “We have a diverse population and it is important staff have a good understanding of people’s needs.
“The award is a great recognition of our work.”
Princess Anne is a patron of the Butler Trust, a charity which encourages positive care of prisoners.