Log Pruner in the AI Toolkit

Log Pruner reduces log search results to a smaller selection of events for investigation. Use Log Pruner after narrowing a search and before reviewing events or passing them to a large language model (LLM).

Log Pruner combines grouping of similar events with semantic ranking powered by the Log Reasoning Foundation Model (LRFM). This helps reduce repetitive log data during investigations and the amount of data passed to an LLM.

In the AI Toolkit, append apply PRUNE to an SPL search to select relevant events. You can provide investigation context and specify the maximum number of events to return. The returned events provide a starting point for analysis. Validate your findings against the original search results because pruning can omit useful evidence.

Use cases

You can use Log Pruner to reduce the number of log events you need to review in the following scenarios:

Use case Description
Investigate an incident Search the affected service, host, or application over the incident time window, then select a smaller set of events to review.
Triage a security alert Search the entities and time window associated with an alert, then provide the alert or investigation question as context.
Prepare LLM context Prune candidate log events before passing them to an LLM for further analysis. Compare the resulting token count with the downstream model's context budget.

Requirements

Before using Log Pruner, make sure you meet the following requirements:

  • Use AI Toolkit version 6.3 or higher in an environment where Log Pruner is available and configured. Contact your administrator to confirm access.

  • Make sure you have permission to search the indexes and events required for your investigation.

  • Prepare an SPL search that returns log events. Apply index, time, and entity filters before using apply PRUNE.

  • Make sure the candidate events and investigation context are within the input and payload limits described in Limits and usage considerations.

Get started with Log Pruner

The following example uses Log Pruner to investigate payment failures by reducing a set of log events to a smaller selection for analysis.

Replace app_logs, service.name, and paymentservice with the index, field, and service value used in your deployment.

To use Log Pruner to investigate payment failures, follow these steps:

  1. Run a scoped search to retrieve the events you want to investigate. Review the results to confirm that the search returns the expected events.

    The following search retrieves log events for the payment service over the last 15 minutes:
    CODE
    index=app_logs earliest=-15m latest=now service.name="paymentservice"
  2. Append apply PRUNE to the search and provide a JSON object describing your investigation question.

    The following search uses apply PRUNE to select events relevant to the payment-failure investigation:
    JSON
    index=app_logs earliest=-15m latest=now service.name="paymentservice"
    | apply PRUNE context='{"query":"Why are payments failing?"}'
  3. Review the returned events. By default, Log Pruner returns a maximum of 100 events. The actual number of events returned might be lower.

  4. To specify a different maximum number of events, use the max_output_count parameter. For example, set max_output_count=50 to return a maximum of 50 events.

  5. Use the returned events to guide your investigation. Run the original search without apply PRUNE to examine surrounding events and validate your findings.

The search preceding apply PRUNE determines which events are considered for pruning. The context parameter provides additional investigation information but does not replace SPL search filters.

Log pruner syntax and parameters

Use the following syntax to apply Log Pruner to an SPL search:
CODE
<search> | apply PRUNE [max_output_count=<int>] [context=<JSON object>]

The <search> placeholder represents an SPL search that returns candidate log events. Angle brackets indicate placeholders, and square brackets indicate optional parameters. Do not include the brackets when entering the search. Enter PRUNE in uppercase.

The following table describes the parameters you can use with apply PRUNE:

Parameter Type Default Description
max_output_count Integer 100 Optional. Specifies the maximum number of events to return. Valid values are 1 through 10,000, inclusive. The actual number of returned events might be lower.
context JSON object None Optional. Provides an investigation question, alert, or other investigation information, including known entities. The JSON object is passed to Log Pruner unchanged.

Provide investigation context

Use the context parameter to provide information about your investigation. You can include a question and known entities, such as a service or namespace.

The following example provides a question about payment failures:

JSON
{
  "query": "Why are payments failing?"
}

The following example includes the investigation question and known service and namespace values:

JSON
{
  "query": "Why are payments failing?",
  "entities": [
    {
      "name": "service.name",
      "value": ["paymentservice"]
    },
    {
      "name": "namespace",
      "value": ["demo-env"]
    }
  ]
}

The query and entities keys are examples and do not define a required schema. In the second example, value is an array.

Include relevant information you already know about the investigation, such as a service, namespace, cluster, pod, or error. Use the preceding SPL search to determine which events are considered for pruning.

When including JSON in an SPL search, enclose the JSON object in single quotation marks and use double quotation marks for JSON keys and string values. Provide a JSON object rather than an array or plain text.

Log pruner examples

The following examples show how to use Log Pruner for different investigation scenarios. The indexes and fields are illustrative. Replace them with values from your environment. Before running an example with apply PRUNE, run the corresponding search without pruning to review the candidate events.

Return up to 50 events for an incident

Use the max_output_count parameter to return a smaller selection of events for an initial review of an incident.

The following example returns up to 50 events related to payment failures:
JSON
index=app_logs earliest=-15m latest=now service.name="paymentservice"
| apply PRUNE max_output_count=50
    context='{"query":"Why are payments failing?"}'

The search returns a selection of up to 50 events from the candidate search results. Increase max_output_count or refine the search if you need more evidence.

Include a known service and namespace

Scope the search to a service and namespace, then include those entities in the context parameter.

The following example selects up to 50 events related to payment failures for a specified service and namespace:
JSON
index=app_logs earliest=-15m latest=now
    service.name="paymentservice" namespace="demo-env"
| apply PRUNE max_output_count=50
    context='{"query":"Why are payments failing?","entities":[{"name":"service.name","value":["paymentservice"]},{"name":"namespace","value":["demo-env"]}]}'

The search returns up to 50 events from the specified service and namespace. The entity names in the context parameter must reflect the information available in your investigation.

Use the sort command after apply PRUNE to display retained events in chronological order.

The following example selects up to 100 events related to authentication failures on a specified host and sorts them from earliest to latest:
JSON
index=security_logs earliest=-30m latest=now host="example-host"
| apply PRUNE max_output_count=100
    context='{"query":"What explains the repeated authentication failures on example-host?"}'
| sort 0 _time

The search returns up to 100 retained events, sorted from earliest to latest by _time. The sort command changes the order in which the retained events are displayed but does not affect which events Log Pruner selects.

For more information, see the sortcommand in the Search Reference manual.

Interpret Log Pruner results

Log Pruner returns a selected set of events for further investigation or processing. The output does not provide an explanation of the incident or an LLM-generated summary.

Consider the following when reviewing the results:

  • Event count: The max_output_count parameter specifies the maximum number of events to return. The actual number might be lower.

  • Event ordering: Use a downstream sort command if you need events displayed in a particular order. Log Pruner does not guarantee that retained events are returned newest first.

  • Evidence coverage: Compare retained events with the original search results. Events excluded from the pruned results might still contain useful evidence.

  • Counts and statistics: Use the original search results for exact counts, frequency analysis, and exhaustive checks. Statistics calculated from pruned results apply only to the retained events.

  • LLM context: Measure the serialized size or token count of retained events before passing them to an LLM. Limiting the number of events does not guarantee that the output fits the LLM's context window.

Limits and usage considerations

The following table describes the input and output limits for Log Pruner:

Limit Value Description
Input event count 1,000,000 events Maximum number of input events per request. Narrow the preceding SPL search if the results might exceed this limit.

Request payload

100 MB, including context Input events and investigation context share the payload limit. Large events might cause the request to exceed this limit before reaching the input event limit.
Output event count 10,000 events Maximum number of events that Log Pruner can return. Use max_output_count to specify the output limit. The default is 100 events.
CAUTION: Log Pruner silently drops events that exceed the input event count or request payload limits. A successful search does not guarantee that every matching event was considered. Narrow the preceding SPL search or investigate smaller time windows when the candidate data might exceed these limits.

The max_output_count parameter limits the number of returned events. Reducing this value does not reduce the number of input events or the request payload size.

Best practices for Log Pruner

Consider the following best practices when using Log Pruner:

  • Scope your search. Start with the relevant index and time window. Add filters for services, hosts, namespaces, users, or other entities as appropriate.

  • Provide investigation context. Use the context parameter to specify a concise investigation question and any relevant information you already know.

  • Preserve relevant events. Avoid filtering only for errors when preceding or subsequent events might provide useful investigation context.

  • Start with the default output limit. Review the returned events before adjusting max_output_count based on your investigation requirements.

  • Validate the selected events. Compare retained events with the original search results, particularly when investigating uncommon events or sequences of events.

  • Evaluate the complete workflow. Compare investigation quality, response time, and LLM token usage with and without pruning. Results vary depending on the workload.

Troubleshooting Log Pruner

If you encounter issues when using Log Pruner, use the following table to identify possible causes and corrective actions.

Issue Possible cause or action
PRUNE is unavailable or the request fails during setup Verify that AI Toolkit version 6.3 or higher is installed and Log Pruner is configured and available in your environment. Contact your administrator to confirm access. Retain the search job details and error message for troubleshooting.
Investigation context cannot be parsed or is rejected Check the SPL quotation marks and JSON syntax. Provide a JSON object with double-quoted keys and string values. Try the minimal investigation question example.
Event limit is rejected Set max_output_count to an integer between 1 and 10,000, inclusive.
Fewer events are returned than requested The max_output_count parameter specifies a maximum, not an exact count. Check the preceding SPL search and review the original events if additional evidence is needed.
Results appear incomplete even though the search succeeds Check the input event count and request payload limits. Events exceeding either limit are silently dropped. Narrow the search and compare the results with the original search.
Retained events do not provide enough investigation context Refine the search and investigation context, adjust max_output_count if needed, and review surrounding events in the original search results.
Response time is longer than expected Reduce the search time window or narrow the candidate events. Retain the search scope, input size, output limit, and search job details for troubleshooting.