@speca11y/semantic
v0.2.6
Published
LLM-powered semantic quality analysis for SpecA11y accessibility reports
Readme
@speca11y/semantic
LLM-powered semantic quality analysis for SpecA11y accessibility reports. Enriches heuristic warnings with AI assessments — turning ambiguous flags into actionable verdicts.
Installation
pnpm add @speca11y/semanticInstall the LLM SDK for your provider of choice:
# Anthropic Claude
pnpm add @anthropic-ai/sdk
# OpenAI
pnpm add openai
# Ollama — no SDK needed, uses HTTP APIUsage
import { check } from '@speca11y/core';
import { enrich } from '@speca11y/semantic';
const report = await check(page, { level: 'AA' });
const enriched = await enrich(report, {
provider: { provider: 'anthropic' },
page, // optional — enables element screenshots for vision models
});
for (const entry of enriched.entries) {
for (const result of entry.results) {
if (result.semantic) {
console.log(`${entry.rule.id}: ${result.semantic.verdict} (${result.semantic.confidence})`);
console.log(` ${result.semantic.explanation}`);
if (result.semantic.suggestion) {
console.log(` Suggestion: ${result.semantic.suggestion}`);
}
}
}
}Providers
| Provider | Model (default) | Vision | API Key |
|----------|----------------|--------|---------|
| anthropic | claude-sonnet-4-20250514 | Yes | ANTHROPIC_API_KEY |
| openai | gpt-4o-mini | Yes | OPENAI_API_KEY |
| ollama | llama3.2 / llava (images) | Yes | None |
// Custom model and endpoint
const enriched = await enrich(report, {
provider: {
provider: 'ollama',
model: 'mistral',
baseUrl: 'http://localhost:11434',
},
});Semantic Annotations
Each enriched result gets a semantic property:
interface SemanticAnnotation {
verdict: 'good' | 'poor' | 'unclear';
confidence: number; // 0–1
explanation: string;
suggestion?: string;
provider: string;
model: string;
}good— the element passes semantic review (e.g., alt text is descriptive)poor— the element has a real accessibility issueunclear— the LLM could not determine quality with confidence
Targeted Rules
Only warnings from these rules are sent to the LLM:
img-alt-quality— image alt text qualitylink-name-quality— link text descriptivenesslabel-quality— form label claritylang-mismatch— content language consistencybutton-name— button label qualitydocument-title— page title descriptivenessvideo-caption-quality— video caption adequacyframe-title— iframe title qualityempty-heading— heading content presence
Options
interface EnrichOptions {
provider: ProviderConfig;
page?: Page; // Playwright page for screenshots
rules?: string[]; // Override which rules to enrich
concurrency?: number; // Max parallel LLM calls (default: 5)
}License
MIT
