0
0
Prompt Engineering / GenAIml~10 mins

PII detection and redaction in Prompt Engineering / GenAI - Interactive Code Practice

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

Complete the code to detect PII entities in the text using a pre-trained model.

Prompt Engineering / GenAI
entities = model.[1](text)
Drag options to blanks, or click blank then click option'
Apredict
Bfit
Ctransform
Dcompile
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'fit' instead of 'predict' which trains the model, not detects.
2fill in blank
medium

Complete the code to replace detected PII entities with a redaction token.

Prompt Engineering / GenAI
redacted_text = text.replace(entity.value, [1])
Drag options to blanks, or click blank then click option'
A'[REDACTED]'
Bentity
Ctext
DNone
Attempts:
3 left
💡 Hint
Common Mistakes
Replacing with the entity itself does not redact anything.
3fill in blank
hard

Fix the error in the code to correctly iterate over detected PII entities.

Prompt Engineering / GenAI
for entity in [1]:
    print(entity)
Drag options to blanks, or click blank then click option'
Amodel
Bredacted_text
Centities
Dtext
Attempts:
3 left
💡 Hint
Common Mistakes
Looping over the raw text string instead of the entities list.
4fill in blank
hard

Fill both blanks to create a dictionary mapping PII types to their counts.

Prompt Engineering / GenAI
pii_counts = {entity.[1]: pii_entities.[2](entity) for entity in pii_entities}
Drag options to blanks, or click blank then click option'
Atype
Bcount
Cindex
Dappend
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'index' or 'append' which do not count occurrences.
5fill in blank
hard

Fill all three blanks to filter PII entities by confidence score and redact them.

Prompt Engineering / GenAI
for entity in entities:
    if entity.[1] > [2]:
        text = text.replace(entity.[3], '[REDACTED]')
Drag options to blanks, or click blank then click option'
Aconfidence
B0.8
Ctext
Dvalue
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong attribute names like 'text' instead of 'value' for replacement.