Think about the urine anion gap much as you think about the serum anion gap. The urine anion gap is really determining unmeasured anions – unmeasured cations. The major unmeasured cation in the urine is ammonium ion, which is how the kidneys get rid of an organic acid load. In the setting of diarrhea, the kidney (assuming it is functioning properly) is working to increase acid secretion and therefore there is a large amount of urine ammonium and thus a largely negative anion gap. In contrast, in a situation such as renal tubular acidosis during which acid secretion is inhibited, the urine ammonium will be low and there will be a positive urine anion gap.
This system breaks down some in some instances–for example, in toluene toxicity during which a large amount of an intact, undissociated acid (hippurate) is being secreted without ammonium. Furthermore, one big knock on regular use of the urine anion gap is that in most cases, the history alone will tell you whether or not a patient’s metabolic acidosis has GI versus renal origins.