Skip to main content
Hello and welcome back. In this lesson we’ll open our Python auditor and make the single change that prevents the LLM output from getting truncated. You’ll see exactly where to change the max_tokens parameter, why it mattered in this case, and how to choose an appropriate value for your project. Expose the Kubernetes cluster to the container (run locally in your terminal):
Helpful references: Why the audit was truncated
  • The earlier truncation was caused by the LLM response being capped by the max_tokens parameter passed to the agent call.
  • To fix this, open structured_auditor.py, find the prompt definition and the run_agent call, and increase the max_tokens value (examples below).
  • Always ensure the sum of prompt tokens and desired response tokens stays within your model’s maximum context size.
The relevant prompt and the code that wires it into the agent (kept concise) are shown here:
Choose max_tokens based on the length of the expected output and your cost/latency trade-offs. If you need exhaustive, untruncated output, increase the limit; if you only need summaries, consider restructuring the prompt to produce shorter, structured outputs (e.g., JSON).
Updating the token limit
  • In this demo I doubled the output token budget from 2048 to 4096. Make sure the model you use supports that many tokens (prompt + output combined) or the request may be rejected or still truncated.
  • Edit the run_agent call in structured_auditor.py to set max_tokens=4096:
Setting a large max_tokens increases cost and can impact latency. Also confirm your model’s maximum context length (prompt + completion) before raising this value. Consider structured outputs (JSON), streaming, or limiting scope as alternatives.
After updating the file (e.g., open in Vim, edit max_tokens, save) and re-running the script, the audit output was no longer cut off and included the full resource-by-resource details and summary sections. Excerpt of the improved audit output (as printed by the program):
The report now includes the full tag coverage and critical observations:
  • Fully Compliant Resources: 0
  • Non-Compliant Resources: 27 (100%)

Tag Coverage Analysis

Critical Observations

  1. Slack-channel Tag: This tag is completely absent across all 27 resources (0% coverage). This is a critical gap for FinOps governance and operational alerting.
  2. System-Generated Resources: All kube-root-ca.crt ConfigMaps across namespaces lack any labels. These are system-generated resources but still appear in the audit scope.
  3. Inventory Namespace Excellence: The inventory namespace demonstrates the highest compliance with 5 of 6 required tags present on most resources. Only the slack-channel tag is missing.
  4. Payment Namespace Inconsistency: The payment namespace shows inconsistent labeling patterns. Some resources have owner and environment tags while others lack application tags entirely.
  5. Default Namespace: The default namespace contains multiple untracked resources (analytics-collector, untracked-config, analytics-data) with minimal or no labels, suggesting these may be orphaned or legacy resources.
Before increasing max_tokens further, consider these alternatives to reduce output length or avoid higher costs:
  • Request machine-readable output (JSON) so the agent produces concise, parseable results.
  • Stream results incrementally if supported by your LLM client.
  • Limit audit scope (fewer namespaces or resource types) to reduce output size.
  • Summarize results at higher level and request drilling only for problematic namespaces/resources.
Guidance for picking max_tokens For model-specific token/context limits and best practices, check your LLM provider’s documentation (for example, see the model token limits in your provider’s docs). A future whiteboarding session will decide the audit output format (human-readable vs. structured) and discuss downstream automation for remediation and reporting.

Watch Video

Practice Lab