Bird
Raised Fist0
MLOpsdevops~20 mins

Data validation in CI pipeline in MLOps - Practice Problems & Coding Challenges

Choose your learning style10 modes available

Start learning this pattern below

Jump into concepts and practice - no test required

or
Recommended
Test this pattern10 questions across easy, medium, and hard to know if this pattern is strong
Challenge - 5 Problems
🎖️
Data Validation Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
🧠 Conceptual
intermediate
2:00remaining
Purpose of Data Validation in CI Pipeline

Why is data validation important in a Continuous Integration (CI) pipeline for machine learning projects?

ATo speed up the model training by skipping data checks
BTo reduce the size of the dataset by removing random samples
CTo automatically deploy models without human review
DTo ensure that the data used for training meets quality standards before model training starts
Attempts:
2 left
💡 Hint

Think about what could happen if bad data enters the training process.

💻 Command Output
intermediate
2:00remaining
Output of Data Validation Step in CI

What is the expected output when a data validation step in a CI pipeline detects missing values in a critical feature?

MLOps
run_data_validation --input data.csv --check missing_values
ASyntaxError: invalid syntax in command.
BValidation passed: No missing values detected.
CValidation failed: Missing values found in column 'age'.
DError: File not found 'data.csv'.
Attempts:
2 left
💡 Hint

Consider what happens if the validation finds a problem in the data.

Configuration
advanced
2:30remaining
Configuring Data Validation in a CI YAML Pipeline

Which YAML snippet correctly configures a data validation step in a CI pipeline that runs a Python script validate_data.py and fails the pipeline if validation fails?

A
steps:
  - name: Data Validation
    run: python validate_data.py
B
steps:
  - name: Data Validation
    run: python validate_data.py
    fail-on-error: true
C
steps:
  - name: Data Validation
    run: python validate_data.py
    continue-on-error: true
D
steps:
  - name: Data Validation
    run: python validate_data.py
    fail-fast: true
Attempts:
2 left
💡 Hint

By default, CI steps fail if the command exits with an error code.

Troubleshoot
advanced
2:30remaining
Troubleshooting Data Validation Failure in CI

A CI pipeline data validation step fails with the error: KeyError: 'target_column'. What is the most likely cause?

AThe dataset does not contain the required 'target_column' feature.
BThe validation script has a syntax error in the code.
CThe CI runner does not have Python installed.
DThe pipeline configuration YAML is missing the data validation step.
Attempts:
2 left
💡 Hint

KeyError usually means a missing key in a dictionary or dataframe column.

🔀 Workflow
expert
3:00remaining
Order of Steps in a CI Pipeline with Data Validation

What is the correct order of steps in a CI pipeline that includes data validation, model training, and deployment?

A2,1,3
B2,3,1
C1,2,3
D3,2,1
Attempts:
2 left
💡 Hint

Think about what must happen before training and deployment.

Practice

(1/5)
1. What is the main purpose of adding data validation in a CI pipeline for machine learning projects?
easy
A. To speed up the model training process
B. To catch data problems early before training models
C. To reduce the size of the dataset
D. To automatically deploy models to production

Solution

  1. Step 1: Understand the role of CI pipelines

    CI pipelines automate checks and tests to ensure quality before further steps.
  2. Step 2: Identify the purpose of data validation

    Data validation ensures data quality and format correctness to avoid errors in training.
  3. Final Answer:

    To catch data problems early before training models -> Option B
  4. Quick Check:

    Data validation = catch problems early [OK]
Hint: Data validation stops bad data early in pipeline [OK]
Common Mistakes:
  • Thinking validation speeds training
  • Confusing validation with deployment
  • Assuming validation reduces data size
2. Which of the following is the correct way to fail a CI pipeline step if a data validation script returns a non-zero exit code in a bash script?
easy
A. python validate_data.py || exit 1
B. python validate_data.py && exit 1
C. python validate_data.py; exit 0
D. python validate_data.py | exit 1

Solution

  1. Step 1: Understand bash exit codes and operators

    The '||' operator runs the command after it if the first command fails (non-zero exit).
  2. Step 2: Apply to data validation script

    If 'validate_data.py' fails, 'exit 1' stops the pipeline with error.
  3. Final Answer:

    python validate_data.py || exit 1 -> Option A
  4. Quick Check:

    Fail on error = '|| exit 1' [OK]
Hint: Use '|| exit 1' to fail on script error [OK]
Common Mistakes:
  • Using '&&' instead of '||' to fail
  • Using pipe '|' incorrectly
  • Exiting with 0 always
3. Given this Python snippet in a CI pipeline step:
import sys

def validate(data):
    if not data or len(data) < 5:
        return False
    return True

if __name__ == '__main__':
    data = sys.argv[1] if len(sys.argv) > 1 else ''
    if validate(data):
        print('Validation passed')
        sys.exit(0)
    else:
        print('Validation failed')
        sys.exit(1)
What will be the output and exit code if the pipeline runs python validate.py "abc"?
medium
A. Validation failed and exit code 0
B. Validation passed and exit code 0
C. Validation passed and exit code 1
D. Validation failed and exit code 1

Solution

  1. Step 1: Check input data length

    Input is 'abc' which length is 3, less than 5, so validate returns False.
  2. Step 2: Determine output and exit code

    Since validate returns False, it prints 'Validation failed' and exits with code 1.
  3. Final Answer:

    Validation failed and exit code 1 -> Option D
  4. Quick Check:

    Short data fails validation = A [OK]
Hint: Check input length to predict validation result [OK]
Common Mistakes:
  • Assuming any input passes
  • Confusing exit codes 0 and 1
  • Ignoring input length check
4. You have this YAML snippet in a CI pipeline to run data validation:
steps:
  - name: Validate Data
    run: |
      python validate.py data.csv
      echo "Data validation complete"
The pipeline does not fail even when validation.py returns exit code 1. What is the likely problem?
medium
A. The shell does not stop on errors by default; need 'set -e'
B. The 'if' condition is incorrect and never triggers
C. The 'exit 1' is inside the if but the script continues after
D. The validate.py script always returns 0

Solution

  1. Step 1: Understand shell error handling

    By default, shell scripts continue even if a command fails unless 'set -e' is used.
  2. Step 2: Apply to CI step

    Without 'set -e', the script continues after python fails, runs the echo which succeeds, so step exit code is 0.
  3. Final Answer:

    The shell does not stop on errors by default; need 'set -e' -> Option A
  4. Quick Check:

    Use 'set -e' to fail pipeline on errors [OK]
Hint: Add 'set -e' to stop on errors in shell scripts [OK]
Common Mistakes:
  • Assuming exit 1 always stops pipeline
  • Misreading if condition syntax
  • Ignoring shell default behavior
5. You want to add a data validation step in your CI pipeline that checks if a CSV file has no missing values and all numeric columns are within a specific range. Which approach best fits this requirement?
hard
A. Use a shell script with grep to search for empty fields and numeric ranges
B. Manually inspect the CSV file before running the pipeline
C. Write a Python script using pandas to check missing values and ranges, then fail with exit code 1 if invalid
D. Skip validation and rely on model training to catch errors

Solution

  1. Step 1: Identify tools for data validation

    Pandas in Python is ideal for checking missing values and numeric ranges programmatically.
  2. Step 2: Implement validation and fail pipeline

    Script should exit with code 1 if validation fails to stop the pipeline safely.
  3. Final Answer:

    Write a Python script using pandas to check missing values and ranges, then fail with exit code 1 if invalid -> Option C
  4. Quick Check:

    Use pandas script + exit 1 for robust validation [OK]
Hint: Use pandas for detailed CSV validation and fail on error [OK]
Common Mistakes:
  • Using grep which can't handle numeric ranges well
  • Relying on manual checks
  • Skipping validation entirely