How it looks
Describe the answer you want as a JSON schema, call uc_ai.generate_text, and write the result to your table. It runs where your data is, inside your transaction and your security model.
Change one parameter to switch provider, or point it at a local Ollama model when data may not leave your network.
declare
l_schema json_object_t := json_object_t(q'#{
"type": "object",
"properties": {
"category": {"type": "string", "enum": ["billing", "bug", "question"]},
"priority": {"type": "string", "enum": ["low", "medium", "high"]},
"summary": {"type": "string"}
},
"required": ["category", "priority", "summary"]
}#');
l_result json_object_t;
l_ticket json_object_t;
begin
for t in (select id, body from support_tickets
where category is null) loop
l_result := uc_ai.generate_text(
p_user_prompt => t.body,
p_system_prompt => 'Classify and summarise this ticket.',
p_provider => uc_ai.c_provider_openai, -- or Anthropic, ...
p_model => uc_ai_openai.c_model_gpt_5_6_luna,
p_response_json_schema => l_schema
);
l_ticket := json_object_t(l_result.get_clob('final_message'));
update support_tickets
set category = l_ticket.get_string('category'),
priority = l_ticket.get_string('priority'),
summary = l_ticket.get_string('summary')
where id = t.id;
end loop;
end;
/