Skip to content
Back to skills

Validate Genai Spans

ASecurity

Use this to check that your LLM tracing actually emits complete, spec-compliant spans, so cost/latency/model dashboards downstream are not full of holes. Trigger on "are my traces complete", "validate my instrumentation", "my spans are missing fields", "lint my OTel GenAI spans", "test my tracing". Ships a runnable, tested validator you can drop into your instrumentation tests.

  • 40 stars
  • 0 votes
  • 0 copies
  • 2 views
  • Added August 31, 2026
ai-agentspython

Security analysis

A100/100

Pro scans all 3 files and shows the line behind each finding

Scanned August 31, 2026

npx -y skills add ContextJet-ai/awesome-llm-observability --skill validate-genai-spans --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Validate Genai Spans?

Add the live security badge to your README. It updates with every re-scan.

Security grade badge for Validate Genai Spans
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/contextjet-ai-validate-genai-spans/badge)](https://www.skillsdirectory.com/skills/contextjet-ai-validate-genai-spans)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

Download with Pro
SKILL.md
---
name: validate-genai-spans
description: Use this to check that your LLM tracing actually emits complete, spec-compliant spans, so cost/latency/model dashboards downstream are not full of holes. Trigger on "are my traces complete", "validate my instrumentation", "my spans are missing fields", "lint my OTel GenAI spans", "test my tracing". Ships a runnable, tested validator you can drop into your instrumentation tests.
license: CC0-1.0
---

# Validate GenAI spans

Broken instrumentation fails silently: the app works, the dashboards just quietly miss the model, the tokens, or the cost. This skill ships a validator that asserts your spans carry the required OpenTelemetry `gen_ai.*` fields, so you catch gaps in a test instead of in a half-empty dashboard.

## Use the bundled script

[`scripts/validate_span.py`](scripts/validate_span.py) is pure Python, no install needed:

```python
from validate_span import validate_gen_ai_span, is_valid_gen_ai_span

problems = validate_gen_ai_span(span_attributes)          # [] means valid
validate_gen_ai_span(span_attributes, strict=True)        # also flag recommended fields
assert is_valid_gen_ai_span(span_attributes)              # use in an instrumentation test
```

It checks the required fields (`gen_ai.system`, `gen_ai.operation.name`, `gen_ai.request.model`) and, in strict mode, the recommended usage fields (`gen_ai.usage.input_tokens`/`output_tokens`, `gen_ai.response.model`) that cost analysis depends on.

## How to apply it

1. **Add an instrumentation test:** capture the span your app emits for a sample call (most SDKs have an in-memory span exporter for tests) and assert `is_valid_gen_ai_span(attrs)`.
2. **Run it in CI** so a change that breaks instrumentation fails the build, not production.
3. **Use strict mode** once basic spans pass, to push toward full cost/usage coverage.

Pairs with `instrument-llm-observability` (which gets the spans emitted in the first place).

## Validation

Run the tests: `pytest skills/validate-genai-spans/tests/`. They cover a valid span, each missing required field, empty/wrong-typed values, strict-mode recommended checks, and non-dict input.

## Anti-patterns

- Assuming "traces show up" means they are complete (missing token fields break cost dashboards).
- Only checking spans by eye once, instead of asserting them in CI.
- Ignoring the response model id (you cannot break cost down by served model without it).

Files in this skill

  • SKILL.md2.4 KB
  • scripts/validate_span.py2.4 KB
  • tests/test_validate_span.py1.3 KB

Attribution

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

Comments

Loading comments…

Newsletter

Get the weekly list of safe new skills, and the ones we pulled.