Skip to main content

Nutrition prompts

Meals & Nutrition has two multimodal extraction tasks and one explicit chat handoff. The image tasks are app-authored user-role content because providers differ in multimodal system-message support. The selected model receives the images, instruction, optional user-entered facts, and a strict JSON schema. The prompt source is js/nutrition-analysis.js. Aggregate history text is built in js/nutrition-summary-context.js.

Shared structured output

Both image paths request one object with this shape:
Every registered nutrient key is present in the provider schema and may be null. Client normalization rejects negative and non-finite values, repairs a narrow set of common JSON formatting failures, rejects truncated/non-actionable output, and makes the result editable before save.
Structured output constrains shape, not factual accuracy. Food identity, recipe, portion, and composition remain estimates unless the user supplies authoritative facts or label values.

nutrition.meal-photo

Triggered by Log meal → Meal photo → Analyze photo and reused for each selected model in Meal Benchmarks.
Optional Known details are appended as user-provided facts and bounded to 500 characters. The instruction tells the model to treat them as authoritative only where they describe the meal. If the user changes an incorrect meal identity and selects recalculate, this correction is appended:

nutrition.label

Triggered by Log meal → Nutrition label → Analyze label and by the label mode in Meal Benchmarks.
The returned label object records the detected serving text, gram/milliliter basis, container servings, label basis, and the user’s consumed amount/unit. Client review remains authoritative before save.

nutrition.history

Triggered by Meals & Nutrition → History → Ask AI after the Meals & Nutrition data source is enabled. This action opens chat with an editable user message; it does not send immediately.
The exact aggregate is generated from the selected range. Individual meal names, notes, ingredients, photos, and response check-ins are omitted. Chat assembly attaches a receipt block that suppresses the automatic nutrition context for this one message so the selected history is not duplicated.

Transport and retention boundary

  • Image tasks send up to four original selected images directly to the chosen image-capable provider only after the user selects analysis.
  • Full-size images are kept only in the in-memory request workspace and are not saved by getbased.
  • The first cloud meal request uses recipient-specific meal-photo consent.
  • Benchmarks reuse one prepared image set across selected models, but every model call has its own abort signal and provider recipient.
  • The selected-history action sends only if the user submits the editable chat message using their current chat provider.

Review checklist

  • Keep meal-photo and label behavior separate; a label path must not invent nutrients absent from the label.
  • Keep unknown values null through schema, parser, review, storage, summaries, targets, and prompt context.
  • Test multiple views of one meal so the model does not double-count them.
  • Test authoritative known details and corrected identity without preserving the earlier estimate as an anchor.
  • Test label bases, dual columns, servings, grams, milliliters, packages, kJ conversion, and salt-to-sodium conversion.
  • Test malformed, extra, partial, truncated, and negative output.
  • Test cancellation and confirm no automatic retry can create an unexpected second provider charge.
  • Confirm full images, user-entered meal facts, and provider output do not enter logs or public fixtures.
  • Confirm selected-history output states its coverage limits and does not duplicate automatic nutrition context.