genai_is_truncated
This page explains how to use the genai_is_truncated function in APL.
The genai_is_truncated function checks whether an AI model response was truncated due to reaching token limits or other constraints. It analyzes the finish reason returned by the API to determine if the response was cut short.
You can use this function to identify incomplete responses, monitor quality issues, detect token limit problems, or track when conversations need continuation.
Usage
Syntax
Parameters
| Name | Type | Required | Description |
|---|---|---|---|
| messages | dynamic | Yes | An array of message objects from a GenAI conversation. Each message typically contains role and content fields. |
| finish_reason | string | Yes | The finish reason returned by the AI API (such as 'stop', 'length', 'content_filter', 'tool_calls'). |
Returns
Returns a boolean value: true if the response was truncated (typically when finish_reason is 'length'), false otherwise.
Example
Check if a GenAI response was truncated due to token limits.
Query
Output
| truncated_count | total_count | truncation_rate |
|---|---|---|
| 45 | 1450 | 3.10 |
This query tracks the rate of truncated responses, helping you identify when token limits are causing quality issues.
List of related functions
- genai_estimate_tokens: Estimates token count. Use this to predict if responses might be truncated before making API calls.
- genai_conversation_turns: Counts conversation turns. Analyze this alongside truncation to understand context length issues.
- genai_extract_assistant_response: Extracts assistant responses. Use this to examine truncated responses.
- strlen: Returns string length. Use this to analyze the length of truncated responses.