← Back to Labs

JSON Schema with tool_use

prompt engineering outputFill in Blank

Complete this API call that uses tool_use to extract structured invoice data. Configure tool_choice to guarantee a tool call, and handle optional fields that may be missing from the source document.

const tools = [
  {
    name: "extract_invoice",
    description: "Extract structured invoice data from the document.",
    input_schema: {
      type: "object",
      properties: {
        vendor_name: { type: "string" },
        invoice_number: { type: "string" },
        total_amount: { type: "number" },
        due_date: { type:  },
      },
      required: ["vendor_name", "invoice_number", "total_amount"],
    },
  },
];

const response = await client.messages.create({
  model: "claude-sonnet-4-20250514",
  max_tokens: 4096,
  messages: [{ role: "user", content: documentText }],
  tools,
  tool_choice: ,
});
Next Exercise →