PMLE Automating and Orchestrating ML Pipelines Practice Question
You are defining a Python function component in KFP SDK v2. Which decorator should you use?
⚠ Common exam trap
The exam often tests the distinction between v1 and v2 decorators, so the trap here is that candidates familiar with KFP SDK v1 may incorrectly choose `@component` (option B) instead of the v2-specific `@dsl.component`.
Answer choices
Why each option matters
Answer the question above first, then reveal the full breakdown to understand why each option is right or wrong.
Correct answer & explanation
✓
@dsl.component
In KFP SDK v2, the `@dsl.component` decorator is used to define a Python function as a lightweight, reusable pipeline component that can be executed independently. This decorator automatically generates a containerized component from the function's signature and type annotations, enabling type-safe inputs and outputs without requiring a separate component YAML specification.
Answer analysis
Option-by-option breakdown
For each option: why learners choose it and why it is or isn't the right answer here.
- ✗
@dsl.task
Why it's wrong here
@dsl.task does not exist in KFP SDK v2; tasks are produced by calling a component inside a pipeline, not by decorating a function. It tempts because task-like naming suggests component creation, and a task decorator would be correct if the SDK exposed one for defining pipeline steps.
- ✗
@component
Why it's wrong here
@component declares a KFP component, but this stem asks about a Python function component, which requires the @dsl.component decorator from the kfp.dsl namespace. @component is tempting because it is the decorator used in KFP v1 pipelines, where that name was correct.
- ✗
@dsl.pipeline
Why it's wrong here
@dsl.pipeline decorates the function that assembles components into a directed acyclic graph; it does not convert a single Python function into a component. It tempts because both decorators wrap Python functions, but the pipeline decorator defines orchestration, which would be right when authoring the workflow itself.
- ✓
@dsl.component
Why this is correct
@dsl.component converts a plain Python function into a lightweight KFP v2 component, automatically inferring its inputs, outputs and container image. This satisfies the requirement to define a function-based component without authoring a separate component YAML specification.
About these practice questions
One of 775 original PMLE practice questions on Courseiva, each with a full explanation and wrong-answer analysis — not exam dumps or protected exam content. Learn why practice questions differ from exam dumps →
JA
Written by Johnson Ajibi, MSc IT Security
Senior Network & Security Engineer · founder of Courseiva
This PMLE practice question is part of Courseiva's free Google Cloud certification practice question bank. Courseiva provides original exam-style practice questions with explanations, topic-based practice, mock exams, readiness tracking, and study analytics to help learners prepare for the PMLE exam.