Defining Your First LLM Endpoint
Explore how to define the minimum behavior for your first LLM endpoint in the Support Ticket Assistant API. Learn to specify request and response formats, enforce clear backend boundaries, and build a safe, human-in-the-loop draft reply to ensure reliable, predictable support automation.
When building LLM features, the first step is defining the minimum endpoint behavior before implementing model calls. In this course, we will build the Support Ticket Assistant API. This service provides an internal, read-only drafting layer between the support tool used by agents and the LLM provider.
Ticket data comes from the upstream ticketing system, while the internal support tool calls the API explicitly. Its primary role is to generate draft responses for support agents. LLMs can produce fluent output that includes incorrect or unsupported claims, a behavior commonly referred to as hallucination. Defining this boundary early gives us a clear interface to enforce with contracts, grounding (constraining outputs to supported source material), and safety controls in later stages.
Where the endpoint starts and stops
To safely ship the first version of the Support Ticket Assistant API, we must draw clear backend boundaries:
Consumers: The API is consumed exclusively by internal support tools.
Inputs: It receives a normalized JSON payload containing the ticket’s plain text body and essential metadata (customer name, product, plan tier, priority).
Outputs: It strictly generates text drafts.
Restrictions: It does not execute state changes. It cannot send emails, update CRM fields, issue refunds, or trigger external API calls.
The minimal safe behavior is a human-in-the-loop draft accompanied by a short rationale. The rationale explains why the draft makes its suggestions, enabling the human agent to quickly verify it against the original ticket content before sending.
What the endpoint must return
With the boundary fixed, we define the request and response at a product level. The initial scope remains tight to ensure failures are easily visible, deliberately excluding attachments, multilingual generation, or billing history lookups.
The request payload:
ticket_text: The plain text body of the customer's messagecustomer_name: The user's name for personalizationproduct: The specific product the ticket addressesplan_tier: The customer's subscription level, which dictates support policies
The response payload (Acceptance criteria):
These criteria must be verifiable product-level checks rather than internal model properties:
draft_reply: A ready-to-send text response. It must explicitly reference details present in the ticket (e.g., an error code) and propose concrete next steps. It must strictly avoid inventing facts or account actions.rationale: Bullet points citing the specific phrases from the ticket that justify the draft's contents.open_questions: A list of missing information required to solve the ticket.
The V1 prompt contract
To make these constraints tangible, we define a prompt template. This serves as the initial contract, forcing the LLM to output observable, structured fields that prevent the model from drifting into ungrounded inventions.
SYSTEMYou draft customer support replies for internal agents to review and send.Restrict your response to actions supported by the provided text.If required information is missing, ask specific questions.USERTicket:{{ticket_text}}Metadata:- customer_name: {{customer_name}}- product: {{product}}- plan_tier: {{plan_tier}}Return exactly:1) draft_reply (ready to send)2) rationale (bullet points referencing the ticket)3) open_questions (bullet points)
The template works because it constrains observable outputs. It names forbidden claims, forces the draft to stay at the level of text, and requires a rationale that reveals whether the output is grounded in the ticket or drifting into invention.
To make the endpoint boundary concrete, the following diagram summarizes the first vertical slice and what moves across the request and response.
Shipping the first vertical slice
With the request and response expectations pinned down, the immediate engineering task is to ship a synchronous API endpoint that returns the correct data shape. In FastAPI, this means creating a POST endpoint that accepts the ticket payload and returns the draft_reply, rationale, and open_questions fields.
Lines 1–2: Import FastAPI and Pydantic’s
BaseModel, the two pieces needed to define a typed endpoint.Line 4: Instantiate the FastAPI app object that routes will attach to.
Lines 6–10: Define the request schema, the four fields from the request payload, as a Pydantic model, so FastAPI validates incoming JSON automatically.
Line 12: Declare a
POSTroute at/draft-reply.Line 13: The handler takes a validated
TicketRequestobject as its only argument.Lines 14–18: Return a hardcoded dict matching the three response fields (
draft_reply,rationale,open_questions), enough to verify the endpoint's shape before any real model call exists.
For this initial vertical slice, we can return a hardcoded response. The hardcoded response is only a temporary implementation, but it lets us verify routing, JSON parsing, response formatting, and client integration. Once the endpoint contract and integration flow are stable, subsequent lessons will add schema validation, structured error handling, and secure calls to the LLM provider.