Request icon
AIAgent icon
GoogleGemini icon
Set icon
Log icon

AI Product Recommender with Structured Output and Dynamic Inputs

Kestra flow with dynamic dropdown inputs that feeds product data to a Gemini agent, enforces a JSON schema on the answer, and stores it in the KV store.

Categories
AI

Turn an LLM opinion into data your pipeline can act on. This Kestra blueprint fetches every product in a category from the DummyJSON demo API, asks a Gemini-powered AI agent to weigh ratings, review sentiment, discounts, and return policies, and forces the answer into a strict JSON schema with title, justification, potentialDownside, and id. Because the output is structured, the flow can immediately store it in the KV store and call the API again to fetch the full record of the recommended product by id. It also demonstrates two UI features worth stealing: dynamic SELECT inputs populated live from an HTTP call, with the product dropdown depending on the chosen category, and task caching so repeated runs on the same data skip the LLM call.

How it works

  1. The category input (SELECT) populates its options at execution time with the Pebble http() function against the DummyJSON categories endpoint. The product input uses dependsOn to re-query options whenever the category changes.
  2. The get_all_products task (io.kestra.plugin.core.http.Request) downloads the full product list for the chosen category, with allowFailed so a bad category does not hard-stop the run.
  3. The recommend_product task (io.kestra.plugin.ai.agent.AIAgent) sends the product JSON to gemini-3.5-flash-lite with weighing criteria in the prompt. responseFormat: JSON plus a jsonSchema with required fields guarantees a machine-readable answer, and taskCache returns the cached recommendation when inputs have not changed.
  4. The store_recommendation_in_kv task (io.kestra.plugin.core.kv.Set) persists the structured answer under the execution id with kvType: JSON.
  5. The get_recommended_product_details task calls the products endpoint with outputs.recommend_product.jsonOutput.id, proving the structured output is directly usable in downstream expressions.
  6. The log_recommendation task (io.kestra.plugin.core.log.Log) prints a human-readable summary ready to forward to Slack or email.

What you get

  • Guaranteed-shape LLM output enforced by a JSON schema, no fragile text parsing.
  • Dynamic, dependent dropdowns that make the flow self-service for non-engineers.
  • LLM response caching via taskCache to cut token spend on repeated runs.
  • A persisted recommendation history in the KV store keyed by execution.

Who it's for

  • E-commerce and merchandising teams prototyping AI-assisted product curation.
  • Data teams that need LLM answers as typed JSON for downstream automation.
  • Anyone learning the structured output and dynamic input patterns of the Kestra AI plugin.

Why orchestrate this with Kestra

The hard part of production LLM use is not the prompt, it is trusting the output enough to chain actions on it. Kestra's AIAgent task enforces the response schema at the platform level, so the downstream HTTP call and KV write can reference jsonOutput.id safely. Dynamic SELECT inputs give the flow a real UI without building a frontend, taskCache deduplicates identical LLM calls, secrets keep the API key out of the YAML, and every recommendation is traceable to the exact product payload the model saw.

Prerequisites

  • A Google AI Studio API key with access to Gemini models.
  • Outbound HTTPS access to dummyjson.com, the free demo product API (no key needed).

Secrets

  • GEMINI_API_KEY: Google Gemini API key used by the AIAgent task.

Quick start

  1. Add the GEMINI_API_KEY secret to your Kestra namespace.
  2. Execute the flow: pick a category and watch the product dropdown repopulate.
  3. Read the structured recommendation in the recommend_product output and the log summary.
  4. Re-run with the same category to see taskCache skip the model call.

How to extend

  • Point the HTTP tasks at your real product catalog or a warehouse-backed API.
  • Send the recommendation to Slack with io.kestra.plugin.notifications.slack.SlackIncomingWebhook.
  • Add price floors or margin rules to the prompt, or post-validate with an If task before publishing.
  • Loop over all categories with ForEach to generate a full recommendation sheet on a schedule.
  • Swap Gemini for OpenAI or Anthropic by changing the provider block, the schema contract stays identical.

Links

Share this Blueprint
See How

New to Kestra?

Use blueprints to kickstart your first workflows.