> ## Documentation Index
> Fetch the complete documentation index at: https://axiom.co/docs/llms.txt
> Use this file to discover all available pages before exploring further.

<AgentInstructions>

## Submitting Feedback

If you encounter incorrect, outdated, or confusing documentation on this page, submit feedback:

POST https://axiom.co/docs/feedback

```json
{
  "path": "/apl/scalar-functions/genai-functions/genai-is-truncated",
  "feedback": "Description of the issue"
}
```

Only submit feedback when you have something specific and actionable to report.

</AgentInstructions>

# 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.

## For users of other query languages

If you come from other query languages, this section explains how to adjust your existing queries to achieve the same results in APL.

<AccordionGroup>
  <Accordion title="Splunk SPL users">
    In Splunk SPL, you would check the finish\_reason field manually.

    <CodeGroup>
      ```sql Splunk example theme={null}
      | eval is_truncated=if(finish_reason="length", "true", "false")
      ```

      ```kusto APL equivalent theme={null}
      ['ai-logs']
      | extend is_truncated = genai_is_truncated(messages, finish_reason)
      ```
    </CodeGroup>
  </Accordion>

  <Accordion title="ANSI SQL users">
    In ANSI SQL, you would check the finish\_reason field value.

    <CodeGroup>
      ```sql SQL example theme={null}
      SELECT 
        conversation_id,
        CASE WHEN finish_reason = 'length' THEN true ELSE false END as is_truncated
      FROM ai_logs
      ```

      ```kusto APL equivalent theme={null}
      ['ai-logs']
      | extend is_truncated = genai_is_truncated(messages, finish_reason)
      ```
    </CodeGroup>
  </Accordion>
</AccordionGroup>

## Usage

### Syntax

```kusto theme={null}
genai_is_truncated(messages, finish_reason)
```

### 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**

```kusto theme={null}
['otel-demo-genai']
| extend finish_reason = ['attributes.gen_ai.response.finish_reasons']
| extend is_truncated = genai_is_truncated(['attributes.gen_ai.input.messages'], finish_reason)
| summarize 
    truncated_count = countif(is_truncated),
    total_count = count(),
    truncation_rate = round(100.0 * countif(is_truncated) / count(), 2)
```

[Run in Playground](https://play.axiom.co/axiom-play-qf1k/query?initForm=%7B%22apl%22%3A%22%5B%27otel-demo-genai%27%5D%20%7C%20extend%20finish_reason%20%3D%20%5B%27attributes.gen_ai.response.finish_reasons%27%5D%20%7C%20extend%20is_truncated%20%3D%20genai_is_truncated\(%5B%27attributes.gen_ai.input.messages%27%5D%2C%20finish_reason\)%20%7C%20summarize%20truncated_count%20%3D%20countif\(is_truncated\)%2C%20total_count%20%3D%20count\(\)%2C%20truncation_rate%20%3D%20round\(100.0%20*%20countif\(is_truncated\)%20%2F%20count\(\)%2C%202\)%22%7D)

**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](/apl/scalar-functions/genai-functions/genai-estimate-tokens): Estimates token count. Use this to predict if responses might be truncated before making API calls.
* [genai\_conversation\_turns](/apl/scalar-functions/genai-functions/genai-conversation-turns): Counts conversation turns. Analyze this alongside truncation to understand context length issues.
* [genai\_extract\_assistant\_response](/apl/scalar-functions/genai-functions/genai-extract-assistant-response): Extracts assistant responses. Use this to examine truncated responses.
* [strlen](/apl/scalar-functions/string-functions#strlen): Returns string length. Use this to analyze the length of truncated responses.
