Given the context units that went into a prompt and the answer they produced, lasercut estimates how much each unit contributed. When the estimates support it, the library returns a smaller prompt that keeps the units that carried the answer.
uv add lasercut
pip install lasercut
from lasercut import ContextUnit, EstimateConfig, attribute, apply_prune
units = (
ContextUnit("city", "Paris is the capital of France."),
ContextUnit("noise", "A shopping list: milk, bread, eggs."),
)
result = attribute(units, "What is the capital of France?", "Paris.", EstimateConfig())
kept = apply_prune(units, result)- PRUNE. The estimates are tight enough, and a smaller set of units carries enough of the mass, so the prompt can be cut.
- INSUFFICIENT_BUDGET. The call budget ran out before every unit could be placed clearly above or below the keep line.
- NOT_PRUNABLE. The estimates are tight, and no smaller set of units carries enough of the mass to justify a cut.
Black-box estimates need many scorer calls because each coalition is a separate request. Units are treated as interchangeable players in a cooperative game, so the estimate does not encode order or overlap between units. EMBEDDING mode measures agreement between the original answer and a sampled completion, which is a weaker signal than token likelihood. tracllmkit is a GPU research toolkit with a different contract: it wraps several attribution methods behind a permutation count and does not expose a call-budget prune path.
- Castro, Gómez, and Tejada, 2009. Polynomial calculation of the Shapley value based on sampling. Truncated Monte Carlo Shapley.
- TracLLM, USENIX Security 2025. arXiv:2506.04202.
- TokenShapley. arXiv:2507.05261.
- Shapley Context Pruning. arXiv:2607.16209.