Handle every outcome explicitly

When your function returns a union, you need to handle each case.match forces you to handle them all—the compiler won't let you forget.

Exhaustiveness checking ensures you handle every case. Remove a case and watch the compiler tell you.

main.baml
// Using the SmartExtract function from Module 4
// which returns: SuccessfulExtraction | NeedsMoreInfo | CannotProcess

function HandleMessage(msg: string) -> string {
  let result = SmartExtract(msg)

  match result {
    SuccessfulExtraction(s) => "Thanks! I found: " + s.data.name
    NeedsMoreInfo(n) => "I need more details: " + n.question
    CannotProcess(c) => "Sorry, I couldn't process that: " + c.reason
  }
}
Click Run to see the rendered prompt