The Reagan administration received more good news on inflation yesterday as the Labor Department reported that producer prices rose 0.4 percent in July, an annual rate of 51/2 percent.

Administration officials cautioned, however, that the nation's underlying inflation rate is still in the 81/2 percent to 9 percent range, and that the economy remains sluggish.

The price report showed that much of the increase came from a long-expected surge in food prices. If this is excluded, the monthly increase was only 0.1 percent, the lowest since 1976, the Bureau of Labor Statistics reported.

Inflation has slowed markedly in the last few months at both the wholesale and retail level. Producer prices rose at an annual rate of 4.6 percent in May and 6.9 percent in June compared with a rise of 11.8 percent for all of last year.

Murray L. Weidenbaum, chairman of the president's Council of Economic Advisers, said he welcomed the July price report, but he cautioned against trying to "read too much into it." He added that, although the lower producer-price increase "makes good reading," the underlying inflation rate remains too high for him to be satisfied with one month's figures.

Commerce Secretary Malcolm Baldrige echoed Weidenbaum and said "the anti-inflation battle must continue until we have convincing evidence that lasting price stability is being restored."

In more good news for the administration, the Federal Reserve Board reported yesterday that the nation's factories boosted their output in July. The Fed reported industrial production rose 0.3 percent in July after a 0.1 percent drop in June.

A slump in the oil market has been a major factor in the improvement on the price front since President Reagan took office, but other prices also have slowed. Last month's figures showed widespread price moderation outside the food sector, the BLS report said.

Some analysts believe the slowing of the economy since the spring has contributed to the better inflation figures, and so inflation could start to worsen again when the economy picks up. Total output fell by 1.9 percent in the second quarter, and Weidenbaum said this week that the economy could be in a recession now.

However, industrial output, a major component of gross national product, has held up reasonably well for most of this year. Unemployment also showed a surprising drop to 7 percent in July, according to figures released last week.

The Federal Reserve Board reported that the July increase in industrial output largely reflected a "a continuation of the poststrike rebound in coal output."

Consumer goods output was unchanged last month, as a sharp decline in auto and truck production was offset by production increases in home appliances and non-durable goods. A further 10 percent fall in auto production is expected this month, the Fed said.

The overall production level last month was almost the same as the high reached in March, 1979, and was 9.3 percent above the low level of July, 1980, when the economy was in recession.

High interest rates have been a major factor restraining the economy, particularly the housing and autos sectors. Weidenbaum yesterday repeated administration predictions that interest rates should fall before the end of the year as financial markets become convinced that the administration's economic policy is anti-inflationary, and price rises are slowing. So far rates have remained stubbornly high, and have confounded official predictions.

Producer price inflation may bounce back up later this year, economist Rebecca Shillingburt of Evans Economics said yesterday. "The last three months are reflecting the low point in price increases during the inflation cycle," she commented.

After some months of more moderate levels, a surge in consumer food prices is under way. In July these prices rose by 11/2 percent, following a one-half percent increase in the previous month, the BLS report said. Pork prices led the way with a 10.1 percent increase, followed by a 3.8 percent rise in beef and veal prices.

Contrasting with this was a 1 percent drop in finished energy prices, as the indexes for both gasoline and home heating oil declined by 2 percent in July. This was the third consecutive monthly drop in gasoline prices.