David Cameron is to try to build up a cross-party consensus with the aim of guaranteeing that ministers will be able to veto the publication of documents under freedom of information requests in exceptional circumstances.

As 27 memos between the Prince of Wales and ministers in the last government are set to be published, Downing Street indicated that legislation might be introduced to guarantee a blanket ministerial veto over publication.

A change in 2011 means that an absolute veto is now in place, covering correspondence from the monarch, the heir to the throne and the second in line – currently the Queen, the Prince of Wales and the Duke of Cambridge. The memos by the Prince of Wales are being published because the Guardian submitted a freedom of information request before the change in 2011.

But Downing Street is concerned that a ruling by the supreme court in March, which sanctioned the release of the memos, has raised doubts over the ability to veto publication of documents beyond the senior members of the royal family.

No 10 believes the original FoI legislation gave ministers a veto power “in extremis”. It is, sources say, subject to a high bar and has been used on fewer than 10 occasions.

The memos between the heir to the throne and ministers in seven government departments had been blocked by the government, which claimed their publication risked undermining the prince’s “position of political neutrality”, which he could not easily recover once crowned. Some of them contain the prince’s “particularly frank” views, the government said.

Prince Charles's letters: single email set off tussle involving 16 judges' rulings Read more

The government’s attempts to block their release through successive court hearings looks set to cost the taxpayer more than £400,000 in legal fees.

Their publication follows a supreme court ruling in March that the government’s attempts to block release were unlawful. The government revealed in March last year that it had spent £274,481 on lawyers and, following the supreme court’s ruling in the Guardian’s favour, has since been ordered to make an interim payment of £150,000 towards the Guardian’s costs.

The prime minister’s spokesman said the court ruling had led to “some degree of lack of clarity” over the right of ministers to veto publication of such sensitive material. But No 10 added that the prime minister would seek to act with the agreement of the other main political parties and senior parliamentarians.

The spokesman said: “The prime minister’s view around the importance of there being a confidential correspondence between the government and the sovereign and the heir to the throne – that has been recognised in the last parliament. There was a change in 2011 in terms of there being an absolute exemption on those. As was reported at the time of the recent court ruling, there is now some degree of lack of clarity with regard to a slightly distinct area which is to do with the exercise of the ministerial veto which is in the current freedom of information legislation.

“Given that the court ruling has generated some degree of uncertainty in this area this is an issue which the government will look at and consider carefully and thoroughly in the period ahead. Our view remains, as the government has argued during the lengthy legal proceedings, that there is a strong case for the ability to exercise a ministerial veto.”

The spokesman said it was too early to say whether the changes would require legislation. Stressing the need to act on the basis of consensus, the spokesman added: “We would have to look at how that potentially might be done. I hope I am not being unfair in saying that some questions and discussions around how the workings of FOI have been raised across several political parties, on a number of sides of the house. I have no doubt there would be discussions with parliamentarians, some parliamentary committees may well look at this as part of the process of considering how potentially we go forward in this area.”

The letters were between the prince and ministers in the departments of business, innovation and skills; health; children, schools and families; environment, food and rural affairs; culture, media and sport; the Northern Ireland Office and the Cabinet Office.

There has been a decade-long legal battle by the Guardian over access to the memos involving rulings by 16 different judges, stretching from a lowly information tribunal to the supreme court, the highest in the land.

Release of Prince Charles's letters shows the point of freedom of information Read more

The Guardian journalist Rob Evans first lodged a request to see memos between Charles and ministers in various departments when the Freedom of Information Act was in its infancy, coming into effect under Tony Blair at the start of 2005. Blair later berated himself as “a naive, foolish, irresponsible nincompoop” for introducing it.

The requests were originally refused by Whitehall mandarins, who were supported by the information commissioner in a December 2009 ruling.

The Guardian fought on, appealing against that decision. After a six-day hearing at the upper tribunal, judges ruled on 18 September 2012 they should be released after all. But on 16 October 2012 the then attorney general, Dominic Grieve, used a ministerial veto to block the release. That was challenged again by the Guardian, which won at the court of appeal on 12 March 2014. Lord Dyson, the master of the rolls, said Grieve did not have reasonable grounds for issuing the veto “merely because he disagrees with the decision” of the tribunal.

In a final bid to maintain secrecy, the attorney general appealed to the supreme court and lost in a judgment handed down by Lord Neuberger, its president, on 26 March this year.