Always free. For everyone.
Course outline
Module 09 of 20 · AI inputs and outputs

Extract facts with evidence

Preserve missing values and connect extracted fields to source text. This module has 3 lessons and takes about 1h 50m. Each lesson has a practice exercise that runs real Python in your browser and a short quiz.

Start module 09 in the Learning Lab
LESSON 1 OF 3

Represent an unknown value

25 minAI automation
WHAT YOU WILL DO

Extract the first uppercase letter or digit sequence after CODE: and a single space. Return None if there is no match.

Extraction turns source text into fields such as a booking code. If the source does not contain the fact, the field should remain unknown. Guessing makes later steps unreliable.

This toy extractor recognises only the pattern CODE: followed by uppercase letters or digits. It returns the first match, or None. This is a regular expression baseline, not an AI extractor.

A pattern match shows where a value came from but does not prove that the underlying booking is valid.

See it in action

example.pyPython 3
def solve(text):
    import re
    match = re.search(r"\bCODE: ([A-Z0-9]+)\b", text)
    return match.group(1) if match else None
print(solve("Booking CODE: AB12 confirmed"))
Keep this in mind

A pattern match shows where a value came from but does not prove that the underlying booking is valid.

LESSON 2 OF 3

Attach a source quote

25 minAI automation
WHAT YOU WILL DO

For string inputs, return value and evidence only when the non-empty candidate appears exactly in the quote; otherwise return None.

An evidence record can store a candidate value and the source quote supporting it. A reviewer can then inspect the evidence without searching the whole document.

For this narrow exercise, accept a candidate only if it is non-empty and appears exactly inside the quote. Case and punctuation matter. Return the candidate and quote together.

Substring evidence is not semantic proof. The quote may deny the value or refer to someone else, so real extraction needs context review.

See it in action

example.pyPython 3
def solve(candidate, quote):
    if not candidate or candidate not in quote:
        return None
    return {"value":candidate, "evidence":quote}
print(solve("AB12", "Your code is AB12."))
Keep this in mind

Substring evidence is not semantic proof. The quote may deny the value or refer to someone else, so real extraction needs context review.

LESSON 3 OF 3

Practical: Check an extraction packet

60 minAI automation
WHAT YOU WILL DO

For a dictionary packet, require code and date fields with non-empty string values present in string evidence. Return ready for verification or review.

A structured extraction may include several proposed fields. Our packet requires code and date fields, each with a value and an evidence quote. Empty or unsupported values go to review.

Use the same check for both required fields. Reject non-string values and evidence. Additional packet fields are ignored in this limited simulation.

Passing this exercise checks completeness and literal support only. It does not validate dates, booking ownership, or the truth of a claim.

GUIDED PRACTICAL · 60 MIN

Your experiment plan

Use the browser editor or the notebook. All records and AI responses are fictional. No network calls, credentials, or real messages are used.

  1. Create two short fictional booking messages and manually label their fields.
  2. Run the example and predict its result before changing it.
  3. Complete the function in Practice and run the checks. Add your own normal, empty, and failure cases.
  4. Add a quote that mentions the code in a denial and record why a literal check misses the issue.
  5. Save the notebook with your observations and explain one limitation of the simulation.

What to hand in

  • An extraction packet with evidence and a context review note.
  • A test table with inputs, expected outputs, actual outputs, and one revision.
Reflect on your results

Which checks require the authoritative booking system?

The automatic exercise checks the core code behaviour. Review observations and written deliverables yourself or with a mentor.

See it in action

example.pyPython 3
def solve(packet):
    for key in ("code", "date"):
        field = packet.get(key)
        if not isinstance(field, dict):
            return "review"
        value, quote = field.get("value"), field.get("evidence")
        if not isinstance(value, str) or not value.strip() or not isinstance(quote, str) or value not in quote:
            return "review"
    return "ready for verification"
print(solve({"code":{"value":"AB12","evidence":"Code AB12"},"date":{"value":"2026-11-02","evidence":"Date 2026-11-02"}}))
Keep this in mind

Passing this exercise checks completeness and literal support only. It does not validate dates, booking ownership, or the truth of a claim.

ABOUT THE LEARNING LAB

Free, open and run by a nonprofit.

This page is part of AI Automation, a free course of 20 modules and 60 lessons in the engineering.fit( ) Learning Lab. The Learning Lab is built and run by engineering.fit( ), a nonprofit founded by Abdullateef Opeyemi Bakare that helps African engineering students gain research experience. You do not need an account or pay a fee to learn.

Course outline · Project lab · Visit engineering-fit.org