So it runs fine most/some of the time then it gets the little stubborn fits?
To me, erratic behavior is often caused by a clog or partial blockage. For a start I'd disconnect the fuel line at the lift
pump and blow compressed air through it backwards. If your engine is diesel
and has a return line blow through that as well.
To check for a vacuum leak, remove the line between the lift pump and carb/injector and replace it with a hose that goes into a glass jar. Then crank the engine and see if you get bubbles in the fuel when it starts pumping. If you can use a piece of clear line you can see the bubbles travel through the hose which can give you a good idea how many there are.
You can also narrow it down by putting a hose on the intake side of the lift pump and running it straight to a can of fuel. If it fixes the issue then you know the problem is in the tank or line coming from the tank.
A somewhat half assed way of dealing with this issue if you are away from home is to put an electric fuel pump
inline between the lift pump and carb/injector if you have tried everything and still can't figure it out. It is not right and if you have a partial clog there is the risk it turns into a total blockage. However, if that happens you can get enough hose to run the intake of the new pump and run it straight into the tank through a fuel fill. While this is a haphazard approach, it can get you home or to a competent mechanic
somewhere. Just make sure if you put an electric pump
inline that it goes between the lift pump and the carb/injector. If you put it in front of the existing pump there is the risk that if the lift pump diaphragm
leaks/ruptures it will fill the engine oil
sump full of fuel. This is especially dangerous with diesels as it can cause vapors to blow by past the rings and the engine becomes uncontrollable and won't shut off.
Anyway, good luck and hopefully you can just shoot some air through your fuel lines and your problem will go away.