🎓 A1Learner
🔍
0 of 50 lessons completed

Prompt Engineering: Extract Data from Text

Extraction is pulling named facts out of free text. The facts come out in a fixed shape, ready to use.

One message, two facts

A customer message holds an order number and a product. The prompt pulls both out.

Extract the order number and the product from this message. Give the answer as a list.
Message: Hi, I got the wrong lamp, my order was 1043.

Two products in one order

Order 1044 holds two products. The prompt must pull both.

Extract the order number and every product from this message. Give the answer as a list.
Message: Please check order 1044. It has the Trailhead Canvas Tote and the Ember Pour-Over Set.

Example

Extract the customer name, the order number and the product from this message. Give the answer as a list.
Message: I am Tom. I ordered the Hearthstone Desk Lamp yesterday and my order is 1043.

Key points

  • Extraction pulls named facts out of free text.
  • The prompt names the facts to pull. Order number and product are two facts the desk needs.
  • The prompt also names the shape. A list makes the answer easy to check.
  • Extraction only copies what is in the text. A fact that is missing stays missing.
  • The check is simple. Every value in the answer must appear in the message.

This example pulls three facts from one message. Each value can be found in the message. Nothing is added.

Note

A missing fact is not a blank to fill. The model must say it is missing, not guess it.

Try it Yourself

Edit the code, then press Run.

Running is simulated · Rust Playground

Exercise

A message does not give an order number. What should the extracted answer do?