Commerce Secretary Malcolm Baldrige warned Japan today that it risks a U.S. ban on many of its products if it continues public and private policies that build up record trade surpluses and keep its rich markets closed to foreign goods.

Baldrige, speaking at a luncheon in Tokyo Tuesday to Japanese industrialists and government officials, issued the administration's toughest public warning to Japan, which last year had at $50 billion trade surplus with the United States. Baldrige's office released the text of his speech in Washington yesterday.

The speech echoed the tone and content of remarks by congressional visitors to Tokyo over the past year, including Senate Majority Leader Robert Dole (R-Kan.) and Sen. John C. Danforth (R-Mo.), chairman of the Finance Committee's trade panel.

According to the Japanese government, Baldrige carried the same message into his meeting yesterday with Prime Minister Yasuhiro Nakasone.

Baldrige, who is known as the administration hawk on the subject, delivered his message at a time of rising tension on trade. Congress is about to try to override President Reagan's veto of legislation that would protect the U.S. textile, shoe and copper industries from foreign competition, and American negotiators face a Wednesday deadline in contentious talks with the Japanese over their semiconductor trade policies.

Instead of helping Reagan fight congressional protectionism by increasing purchases of foreign-made products, Japanese policies still limit imports, Baldrige said.

"Whether it's soda ash or coal in a declining industry or supercomputers or satellites in a growth, industry, we find the Japanese unwilling to take even our most competitive exports," the commerce secretary said.

He said most Americans, including members of Congress, believe Japan does very little to resolve trade friction except talk. While Nakasone urges the Japanese to import more, Baldrige said, the country follows different policies. He said foreign companies are barred from bidding on an $8 billion public project to build an international airport in Osaka; the government refuses to buy foreign satellites, and a U.S. company -- Cray Computers, the world leader in supercomputers -- has never sold one to a Japanese government bureau or university.

He criticized Japan for failing to take on the responsibilities that go with being an economic power, and said "the second most powerful economy in the free world continues to use its aid program as a sales tool" that requires poor countries to buy what Japanese industry wants to sell them.

Baldrige said the United States is not alone in complaining about Japan's trading practices, citing demands by the European Community, Taiwan and South Korea that Japanese protectionism stop.

"You must resist the temptation to demand protection from imports because your industries are in a developing stage, or because they have excess capacity, or because they are mature, or because the exchange rate has changed, or for 50 other reasons that are protectionist," Baldrige said.

He told the Japanese that the Reagan administration will continue to fight protectionism. "On your side," he continued, "you must take it into your hands to solve your share of the trade problem.

"I greatly fear if you don't a solution will be forced on us that will harm both our countries, but Japan most of all," he said.