Lawfare Academy

AI 320 — Applied AI, Retrieval and Reliable Automation · Weeks 1–2

Choose the task before the tool

Full teaching sequence and cumulative subject work

Study the complete on-site source sections below, then work the original example, changed-condition problem and transfer laboratory. Review CS50 AI Knowledge and Language and the evaluation sections of scikit-learn. Compare a deterministic rule, search and a language-model approach on the same task.

Recover a durable action after the effect–record crash window — primary material, constructed-response tasks, complete worked model and changed-case examination →

Task decomposition before model selection

An AI workflow is a sequence of decisions with different error costs and evidence needs. Exact arithmetic, permission checks and record identity should use deterministic mechanisms with explicit contracts. A language model may help draft or classify, but its output must enter a validation boundary before it controls an action. A polished sentence does not substitute for a verified source or authorization.

Define the task’s allowed outputs and an abstention route. A bounded assistant can decline when the requested evidence is missing. That is meaningful only if downstream code treats abstention differently from an empty but supposedly authoritative answer.

Worked problem

A user asks for the total of three invoices, an explanation of a refund policy, and transmission of a refund request. Design three separate stages.

Trace the complete reasoning
  1. Calculate the invoice total from validated structured amounts with ordinary arithmetic; a generated number is not needed.

  2. Retrieve the relevant policy version, check its applicability and draft an explanation tied to specific passages.

  3. Prepare a proposed refund request separately from sending it. Validate the payload and obtain the required authorization for the actual external action.

  4. If policy evidence is missing or contradictory, abstain or route to review. Do not turn a plausible draft into an approved transaction.

Independent transfer problem

The draft is correct but the recipient changed after approval. Is sending still covered by the prior approval?

Compare the transfer solution

No. Approval must bind the consequential payload, including recipient and relevant amount or record identity. A changed recipient requires a fresh approval under the workflow’s policy. Content quality and action authorization are independent conditions.

Learning objectives

  • Explain and trace the mechanisms in choose the task before the tool.
  • Apply the method to the worked example and changed-condition exercise.
  • Identify assumptions, failure cases and the evidence needed to justify a result.

Study the mechanism

An AI project begins with a task and a reason to use AI. Extracting an invoice total from a consistent structured record may be simpler and more reliable with ordinary parsing than with generative text. Drafting an explanation from varied documents may benefit from language generation, but requires evidence checks. Define inputs, desired output, failure costs and a non-AI baseline.

Separate assistance from action. A draft shown to a person has different consequences from a system that sends a message, changes a balance or deletes a record. Draw the workflow, identify irreversible transitions and decide where explicit approval belongs. An impressive demonstration does not establish error rates on ordinary, difficult and adversarial cases. Measure the work that follows the generated output, including verification and corrections.

Use a bounded initial scope. A support assistant for fictional maintenance policies can answer only from a versioned document set and abstain when no source supports a response. This is a testable contract. An instruction to answer anything confidently is not. Document who maintains sources, how changes are detected and how the system behaves when retrieval or generation is unavailable. A useful prototype can use deterministic retrieval and templated responses before integrating any paid model service.

Worked example

def route_task(task):
    if task == "sum_invoice_rows":
        return "deterministic_calculation"
    if task == "find_policy_passage":
        return "retrieval"
    if task == "draft_policy_explanation":
        return "retrieval_then_reviewed_draft"
    return "clarify_scope"

assert route_task("sum_invoice_rows") == "deterministic_calculation"

The routing function encodes a deliberate decomposition. It does not use a model where arithmetic or lookup is sufficient. The reviewed-draft route still needs source support and cannot imply permission to send the result. An unknown task triggers clarification rather than guessing an action with potentially different consequences.

Check your understanding

When is generative AI least justified?

  1. For exact arithmetic over a well-defined structured table
  2. For every task involving words
  3. Whenever a human can read the result
Answer and reasoning for every option

Correct: For exact arithmetic over a well-defined structured table Deterministic calculation is a clearer baseline for exact totals.

Reconsider: For every task involving words Many text tasks are conventional search or parsing problems.

Reconsider: Whenever a human can read the result Human readability alone does not settle method choice.

Transfer laboratory: A misleading time-saving claim

A tool saves 12 drafting minutes per record, adds 8 review minutes and requires 10 correction hours monthly for 300 records. Compute net monthly labor capacity before fees.

Work through the full solution

Drafting gains 60 hours, review consumes 40 and corrections consume 10, leaving 10 hours of potential capacity. This is not automatically cash savings if wages remain unchanged. Include setup, subscription, monitoring and opportunity to use the freed capacity before calculating economic benefit. Verify all time estimates on representative cases.

Evidence of understanding

Compute ten net hours and distinguish capacity, economic value and cash savings.

Complete on-site teaching readings

These are full attributed source sections, not previews. Read them alongside the original Academy explanation and code.

  1. 3.4. Metrics and scoring: quantifying the quality of predictions · The scikit-learn developers
  2. 12. Common pitfalls and recommended practices · The scikit-learn developers
  3. dataclasses — Data Classes · Python Software Foundation and Python documentation contributors
  4. argparse — Parser for command-line options, arguments and subcommands · Python Software Foundation and Python documentation contributors
  5. Page Summary · Martin Zinkevich and Google Developers contributors

Open in My Learning to record progress →