← All packages

@lacspace/screen

v1.1.0LLM Efficiency0 deps

A cheap lexical content screener and LLM admission gate — score text against your own weighted, multi-language term lexicons (with negation, proximity windows and a named-entity gazetteer) and get a clear / review / block decision, so obviously-clean and obviously-flagged text never reaches an expensive model. Deterministic, auditable, isomorphic.

npm i @lacspace/screen

Usage

screen.ts
import { createScreen } from "@lacspace/screen";

const screen = createScreen({
  dimensions: {
    death:    { terms: ["died", "killed", "\u092e\u0943\u0924\u094d\u092f\u0941"] },
    minor:    { terms: ["child", "\u092c\u093e\u0932\u092c\u093e\u0932\u093f\u0915\u093e"], forceReview: true },
    hate:     { terms: [/* your list */], weight: 3, forceBlock: true },
  },
  negations: ["no", "not", "-\u0928", "-\u0928\u0928\u094d"],
  gazetteer: ["\u0915\u093e\u0920\u092e\u093e\u0921\u094c\u0902"],
  thresholds: { clear: 0, review: 1, block: 5 },
});

const r = screen(storyText);
r.decision; // "clear" | "review" | "block"
if (r.decision === "review") await askTheModel(storyText); // only the uncertain ones reach the LLM

Exports 2

createScreenscreenText

Keywords

content-moderationlexicalscreenertriagellm-gateadmission-controlclassifiernegationgazetteersensitivity

More in LLM Efficiency

@lacspace/condense

Extractive multi-source condenser — turn several articles on one story into a short, deduplicated, token-budgeted digest that keeps the numbers, quotes and named entities, so an LLM only rewrites a fraction of the text. BM25 sentence ranking, near-duplicate removal, per-source attribution with char offsets, Devanagari-aware (।/॥, ०-९, रु). Deterministic, isomorphic.

@lacspace/keyphrase

Extractive keyphrases, tags, hashtags, named entities and category votes — a zero-dependency RAKE + TF-IDF engine with built-in English and Nepali stopwords, Devanagari-aware, so you can stop asking an LLM to generate tags/hashtags/entities. Deterministic, isomorphic.

@lacspace/llm-cache

A content-hash cache for LLM calls — key by (model family, prompt version, normalized input) so identical requests, retries after a 429 and repeated rewrites never pay twice. Pluggable async store (in-memory LRU built in, Mongo/Redis/KV via an adapter), TTL, stale-if-error and a wrap() memoizer. Zero-dependency, isomorphic.

@lacspace/keypool

AI key pooling two ways. createAiChain: route-ordered multi-provider failover (Gemini, Groq, Cerebras, OpenAI, Anthropic, DeepSeek, OpenRouter, any OpenAI-compatible) that rests key+model pairs on 429 (Gemini daily quota until Pacific midnight), quarantines rejected keys (incl. Gemini's 400 'API key not valid'), cools down after N failures, shrinks Groq max_tokens to fit TPM, regrows empty reasoning replies, JSON mode with repair, per-purpose routes and caps, a call ledger hook, and a shared store (memory or Redis). createKeypool: RPM/RPD/TPM/TPD rotation and accounting. Built on @lacspace/ai.