Classify support tickets

Assign a support category to an incoming message.

Create a Canary project first. This example uses OpenAI and requires an OPENAI_API_KEY.

Source

Put this code in baml_src/main.baml:

BAMLclassify-support-tickets.baml
enum Category {
  Refund
  CancelOrder
  TechnicalSupport
  AccountIssue
  Question
}

function classify_message(input: string) -> Category {
  client: openai.ResponsesClient.new(model = "gpt-4.1-mini", api_key = env.OPENAI_API_KEY)
  prompt: `
    ${role("system")}
    Classify the support message into one category.
    ${ctx.output_format()}

    ${role("user")}
    ${input}
  `
}
enum Category {
  Refund
  CancelOrder
  TechnicalSupport
  AccountIssue
  Question
}

function classify_message(input: string) -> Category {
  client: openai.ResponsesClient.new(model = "gpt-4.1-mini", api_key = env.OPENAI_API_KEY)
  prompt: `
    ${role("system")}
    Classify the support message into one category.
    ${ctx.output_format()}

    ${role("user")}
    ${input}
  `
}

Call it

From the project root:

export OPENAI_API_KEY="your-api-key"
baml check
baml run classify_message -- --input "I was charged twice for my order"

The expected category is Refund; model responses can vary.

For Node.js, generate the TypeScript SDK, then call the async export:

import { classify_message_async } from "./baml_sdk/index.js"

export async function classifyTicket(message: string) {
  return await classify_message_async(message)
}

Why this shape

An enum limits the result to the categories you declare. Your application can switch on those values without parsing free-form model text.

Read the function reference for syntax details or expand the same pattern in the structured extraction tutorial.