Skill 3.3.5

Extract language model responses

Key Concepts

The @response output has a response object (HTTP status and headers) and a result object with the model's body. For chat completions, the answer is JSON_VALUE(@response, '$.result.choices[0].message.content'), the reason the model stopped is $.result.choices[0].finish_reason (length means the answer was truncated), and token counts are under $.result.usage. For embeddings, the vector is JSON_QUERY(@response, '$.result.data[0].embedding').

When the request used structured output, the content is itself a JSON string matching the schema, so it is parsed with OPENJSON(@content) WITH (...) into typed columns or stored in a json column. JSON_VALUE returns NULL for values longer than 4,000 characters in lax mode, so long answers are read with OPENJSON and a WITH (content nvarchar(max) '$.content') column definition. The extracted answer and sources are returned to the caller or saved for auditing.