Bird
Raised Fist0
Agentic AIml~10 mins

Input validation and sanitization in Agentic AI - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to check if the input is a non-empty string.

Agentic AI
def is_valid_input(user_input):
    return isinstance(user_input, [1]) and len(user_input) > 0
Drag options to blanks, or click blank then click option'
Astr
Bint
Clist
Ddict
Attempts:
3 left
💡 Hint
Common Mistakes
Using int or list instead of str
Not checking the length of the input
2fill in blank
medium

Complete the code to remove leading and trailing spaces from the input string.

Agentic AI
def sanitize_input(user_input):
    return user_input.[1]()
Drag options to blanks, or click blank then click option'
Areplace
Bsplit
Cstrip
Dlower
Attempts:
3 left
💡 Hint
Common Mistakes
Using split() which splits the string
Using replace() without specifying what to replace
3fill in blank
hard

Fix the error in the code to safely convert input to an integer.

Agentic AI
def convert_to_int(user_input):
    try:
        return [1](user_input)
    except ValueError:
        return None
Drag options to blanks, or click blank then click option'
Abool
Bint
Cfloat
Dstr
Attempts:
3 left
💡 Hint
Common Mistakes
Using str() which does not convert to int
Using float() which converts to decimal numbers
4fill in blank
hard

Fill both blanks to create a dictionary of word lengths for words longer than 3 characters.

Agentic AI
words = ['apple', 'cat', 'banana', 'dog']
lengths = {word: [1] for word in words if len(word) [2] 3}
Drag options to blanks, or click blank then click option'
Alen(word)
B>
C<
Dword
Attempts:
3 left
💡 Hint
Common Mistakes
Using word instead of len(word)
Using < instead of > in the condition
5fill in blank
hard

Fill all three blanks to filter and transform a dictionary with values greater than 0.

Agentic AI
data = {'a': 1, 'b': -2, 'c': 3}
result = {{ [1]: [2] for k, v in data.items() if v [3] 0 }}
Drag options to blanks, or click blank then click option'
Ak.upper()
Bv
C>
Dk
Attempts:
3 left
💡 Hint
Common Mistakes
Using k instead of k.upper()
Using < instead of > in the condition