Portal
SandboxAPI v1Not signed inExternal user: —

Dietary intelligence

Evaluate a recipe against dietary preferences, surface violations, then propose safe alternatives — without inventing diet logic in your client.

What you can build

Dietary filters, “why this isn’t vegan” explainers, one-tap vegetarian transforms, and agent tools that check compatibility before recommending a meal.

1. Pick a recipe and preferences

Preferences are enums: VEGETARIAN, VEGAN, GLUTEN_FREE, DAIRY_FREE. Python uses dietary_preferences; TypeScript uses dietaryPreferences.

page = client.recipes.list(search="chicken chili", limit=5)
recipe_id = page.items[0].id
prefs = ["VEGETARIAN"]

2. Analyze for violations

Goal ANALYSIS returns structured fields including dietary_violations and structured_reasoning. Pair with include_trace=True / includeTrace when you need debugging detail.

analysis = client.reason(
    recipe_id=recipe_id,
    goal="ANALYSIS",
    dietary_preferences=prefs,
    include_trace=False,
)
print(analysis.dietary_violations)
print(analysis.structured_reasoning.ontology_insights)
print(analysis.confidence_score)
{
  "dietary_violations": ["contains animal protein: chicken"],
  "structured_reasoning": {
    "ontology_insights": ["…"],
    "graph_insights": ["…"]
  },
  "confidence_score": 0.91
}

3. Request a transformation proposal

Goal TRANSFORM (via reason) or the recipe transform helpers return a proposal — substitution steps and confidence. Nothing is written back to the stored recipe until your app chooses to create/update one.

plan = client.reason(
    recipe_id=recipe_id,
    goal="TRANSFORM",
    dietary_preferences=prefs,
)
for step in plan.transformation_plan:
    print(step.from_name, "→", step.to_name, step.reason, step.confidence)

# Or the dedicated transform endpoint:
proposal = client.recipes.transform(recipe_id, "VEGETARIAN")
print(proposal.confidence_score)
for line in proposal.transformed_ingredients:
    print(line.from_name, "→", line.to_name)

Transform types include VEGETARIAN, VEGAN, GLUTEN_FREE, DAIRY_FREE, and others. See Recipes.

4. Recommend alternatives

When a transform is not enough, goal RECOMMENDATION ranks alternative recipes under the same dietary context.

recs = client.reason(
    recipe_id=recipe_id,
    goal="RECOMMENDATION",
    dietary_preferences=prefs,
)
for alt in recs.alternative_recipes[:5]:
    print(alt.recipe_id, alt.title, alt.reasons)

Production considerations

  • Show dietary_violations and transform explanations in UI — users trust dietary tools when they see why.
  • Proposals are not mutations. Persist only after the user accepts (create a new recipe or update via CRUD).
  • Agents can call MCP check_dietary_compatibility and transform_recipe with the appropriate recipe/nutrition scopes. MCP tools

Next

Keep building dietary UX