Skill 3.3.4

Send results to language model

Key Concepts

The JSON produced from the retrieved rows is placed in the user message (or a separate message) of the payload, and the payload is passed to sp_invoke_external_rest_endpoint with a managed identity credential. The procedure's return value is 0 for a 2xx status; otherwise it returns the HTTP status code, and the response JSON's $.response.status.http.code confirms it. Error handling distinguishes 429 (throttled; retry with backoff), 400 (bad request, such as an oversized prompt) and 401 or 403 (identity or role problems).

A RAG stored procedure typically embeds the question, runs vector or hybrid search, serializes the top results, calls the model and returns the answer and the source IDs. Wrapping these steps in one procedure lets applications, Data API builder and agents call the RAG pipeline with one EXECUTE, and logging the prompt size, latency and status code in a table supports monitoring.