<@ULVA73B9P> how can I get the input parameters to...
# ask-marvin
f
@Marvin how can I get the input parameters to a task run from the TaskRun ? when inspecting task_run.task_inputs it has only empty lists
m
thought for 354.8 seconds
Short answer: you typically can’t get the actual argument values from a TaskRun after the fact. In Prefect 3.x,
task_run.task_inputs
is for dependency tracking (references), not value capture, so it’s expected to be empty lists when arguments were literals or not wired from upstream tasks/parameters. What
task_inputs
is - It’s a mapping of task argument names to a list of “input links” (e.g., references to a flow parameter or an upstream task’s result). It does not store the concrete values. - If your task args were plain Python literals (e.g.,
my_task(5, "foo")
), there’s no dependency to record, so
task_inputs['x'] == []
is expected. - If inputs come from flow parameters or upstream tasks, you may see
RunInput
references like Parameter or TaskRunResult which tell you the source, not the value. Ways to recover or capture inputs - If the input was a flow parameter: fetch the flow run and read its parameters, then use
task_run.task_inputs
to map which parameter fed which arg. There’s no direct “task inputs = values” endpoint. - REST docs: https://docs-3.prefect.io/v3/api-ref/rest-api/server/task-runs/ - Python client/API docs: https://docs-3.prefect.io/v3/api-ref/python/client/ - TaskRun model: https://docs-3.prefect.io/v3/api-ref/python/client-schemas/#prefect.client.schemas.objects.TaskRun - If the input came from an upstream task: you’ll need that upstream task’s persisted result to reconstruct the value. If results weren’t persisted, Prefect won’t have the value later. - If the input was a literal: Prefect does not store it. To make inputs available later, log or emit an artifact at task start. Examples to capture inputs going forward - Log them:
Copy code
from prefect import task, get_run_logger

  @task
  def my_task(x, y):
      logger = get_run_logger()
      <http://logger.info|logger.info>(f"inputs: x={x!r}, y={y!r}")
- Emit an artifact with the inputs:
Copy code
from prefect import task, get_run_context
  from prefect.artifacts import create_markdown_artifact

  @task
  def my_task(x, y):
      ctx = get_run_context()
      create_markdown_artifact(
          key=f"inputs/{ctx.task_run.id}",
          markdown=f"Inputs\n- x: {x!r}\n- y: {y!r}"
      )
Artifact docs: https://docs-3.prefect.io/v3/api-ref/python/artifacts/ If you can share how your task is invoked (from parameters vs upstream tasks vs literals), I can suggest the exact steps to reconstruct what’s possible for your runs.