Skip to content
Back to skills

Sentence Truncation Fallback

ASecurity

Truncate LLM output to exactly N sentences and fall back to a known-good baseline string when output is empty or too short

  • 61 stars
  • 0 votes
  • 0 copies
  • 3 views
  • Added September 12, 2026
businesspythongo

Security analysis

A100/100

Scanned September 12, 2026

npx -y skills add wenmin-wu/ds-skills --skill sentence-truncation-fallback --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Sentence Truncation Fallback?

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

Security grade badge for Sentence Truncation Fallback
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/wenmin-wu-sentence-truncation-fallback/badge)](https://www.skillsdirectory.com/skills/wenmin-wu-sentence-truncation-fallback)

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: llm-sentence-truncation-fallback
description: Truncate LLM output to exactly N sentences and fall back to a known-good baseline string when output is empty or too short
---

# Sentence Truncation with Fallback

## Overview

LLM outputs for structured tasks (prompt recovery, classification rationale, single-line answers) often include unwanted preamble, repetition, or rambling. Truncate to the first N sentences, then check length — if the result is too short or empty, substitute a well-scoring baseline string. This two-step post-processing ensures consistent submission quality.

## Quick Start

```python
import re

BASELINE = "Improve the following text using a more formal and academic tone while maintaining the original meaning"

def truncate_sentences(text, max_sentences=1):
    sentences = re.split(r'(?<=[.!?])\s+', text.strip())
    result = ' '.join(sentences[:max_sentences])
    return result

def postprocess(raw_output, min_length=15):
    cleaned = truncate_sentences(raw_output, max_sentences=1)
    cleaned = cleaned.strip().strip('"').strip("'")
    if len(cleaned) < min_length:
        return BASELINE
    return cleaned

predictions = [postprocess(output) for output in raw_outputs]
```

## Workflow

1. Split raw LLM output by sentence boundaries
2. Keep only the first N sentences (typically 1 for single-prompt tasks)
3. Strip quotes, whitespace, and formatting artifacts
4. Check minimum length — outputs under threshold are likely garbage
5. Replace short/empty outputs with a high-scoring baseline string

## Key Decisions

- **Baseline string**: use a generic, broadly applicable prompt that scores well on average (~0.60+ similarity)
- **min_length**: 15-20 characters filters out single-word or empty outputs
- **Sentence count**: 1 for prompt recovery; 2-3 for summaries or explanations
- **Combine with timeout**: apply fallback also when inference exceeds time budget

## References

- [Mistral 7B Prompt Recovery Version 2](https://www.kaggle.com/code/richolson/mistral-7b-prompt-recovery-version-2)

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…