policy-qa
БесплатноБез исполняемых скриптовНе проверенAnswer policy questions with strict citations. Refuses to answer without sources.
от FDU-INS★ 84 звезды на GitHubОб этом скилле
Policy Q&A Skill
Purpose
Answer policy and SOP questions with strict source attribution. Refuses to answer without relevant sources. Designed for compliance-sensitive environments.
Usage
# Ask policy question
answer = policy_qa(
question="What is the approval workflow for journal entries over $100K?",
top_k=5,
min_confidence=0.8
)
Workflow
1. Embed Question
from sentence_transformers import SentenceTransformer
def embed_question(question, model_name='sentence-transformers/all-MiniLM-L6-v2'):
"""Embed question using same model as policy corpus"""
model = SentenceTransformer(model_name)
embedding = model.encode(question)
return embedding.tolist()
2. Retrieve from pgvector
import psycopg2
def retrieve_policy_sources(question_embedding, top_k=5):
"""Retrieve similar policy chunks from pgvector"""
conn = psycopg2.connect(os.environ['POSTGRES_URL'])
cursor = conn.cursor()
# Vector similarity search
query = """
SELECT
id,
text,
document_name,
section,
page_number,
url,
1 - (embedding <=> %s::vector) AS similarity
FROM policy_chunks
WHERE 1 - (embedding <=> %s::vector) > 0.3 -- Minimum similarity threshold
ORDER BY embedding <=> %s::vector
LIMIT %s
"""
cursor.execute(query, (question_embedding, question_embedding, question_embedding, top_k))
results = cursor.fetchall()
cursor.close()
conn.close()
return [{
'id': r[0],
'text': r[1],
'document_name': r[2],
'section': r[3],
'page_number': r[4],
'url': r[5],
'similarity': r[6],
} for r in results]
3. Rank by Relevance
def rank_sources(sources, question):
"""Re-rank sources by relevance using cross-encoder"""
from sentence_transformers import CrossEncoder
model = CrossEncoder('cross-encoder/ms-marco-MiniLM-L-6-v2')
# Score each source
pairs = [[question, s['text']] for s in sources]
scores = model.predict(pairs)
# Add scores to sources
for source, score in zip(sources, scores):
source['relevance_score'] = float(score)
# Sort by relevance
sources.sort(key=lambda x: x['relevance_score'], reverse=True)
return sources
4. Check Confidence Threshold
def check_confidence(sources, min_confidence=0.8):
"""Check if top source meets confidence threshold"""
if not sources:
return False, "No relevant sources found"
top_score = sources[0]['relevance_score']
if top_score < min_confidence:
return False, f"Low confidence ({top_score:.2f} < {min_confidence})"
return True, None
5. Generate Answer with Citations
def generate_answer_with_citations(question, sources):
"""Generate answer citing specific sources"""
# Build context from top sources
context = "\n\n".join([
f"[{i+1}] {s['document_name']}, Section: {s['section']}, Page: {s['page_number']}\n{s['text']}"
for i, s in enumerate(sources[:3]) # Use top 3 sources
])
# Prompt for answer generation
prompt = f"""
Answer the following question based ONLY on the provided policy documents.
You MUST cite your sources using [1], [2], [3] notation.
Question: {question}
Policy Documents:
{context}
Instructions:
- Answer the question using only information from the provided documents
- Cite sources inline using [1], [2], [3]
- If the documents don't contain the answer, say "I cannot find relevant policy guidance"
- Be specific about policy requirements, procedures, approvals
- Quote exact text when citing requirements
Answer:
"""
# Generate answer (using LLM)
answer = call_llm(prompt)
# Verify citations are present
if not any(f'[{i+1}]' in answer for i in range(len(sources[:3]))):
return "I cannot provide an answer without proper citations."
return answer
def call_llm(prompt):
"""Call LLM API (e.g., Claude, GPT, or local model)"""
# Implementation depends on LLM choice
pass
6. Format Response with Sources
def format_response(answer, sources):
"""Format response with full source references"""
response = answer + "\n\n---\n\n**Sources:**\n\n"
for i, source in enumerate(sources[:3], start=1):
response += f"[{i}] **{source['document_name']}**\n"
response += f" Section: {source['section']}\n"
response += f" Page: {source['page_number']}\n"
response += f" URL: {source['url']}\n"
response += f" Relevance: {source['relevance_score']:.2f}\n\n"
return response
7. Audit Logging
def log_policy_qa(user, question, sources, answer, refused=False):
"""Log policy Q&A for audit trail"""
import psycopg2
from datetime import datetime
conn = psycopg2.connect(os.environ['POSTGRES_
Установить policy-qa в Claude Code и Claude Desktop
Зарегайся, чтобы установить скилл
Создай бесплатный аккаунт, чтобы открыть команду установки и сохранить скилл в библиотеку.
- Открой команду установки в одну строку
- Сохраняй скиллы в синхронизируемую библиотеку
- Уведомления, когда скиллы обновляются
Разрешённые инструменты
Инструменты, которые скиллу разрешено вызывать.
Без ограничений — скилл может использовать любой инструмент.
Вложенные файлы
FAQ
Что делает скилл policy-qa?
Answer policy questions with strict citations. Refuses to answer without sources.
Как установить скилл policy-qa?
Скопируй папку скилла в ~/.claude/skills (вкладка Claude Code выше делает это одной командой), либо поставь как плагин.
Скилл policy-qa запускает скрипты?
Нет, скилл состоит только из инструкций (SKILL.md), без исполняемых скриптов.
Похожие скиллы
theme-factory
Toolkit for styling artifacts with a theme. These artifacts can be slides, docs, reportings, HTML landing pages, etc. There are 10 pre-set themes with…
от Anthropicaccess
Manage Discord channel access — approve pairings, edit allowlists, set DM/group policy. Use when the user asks to pair, approve someone, check who's allowed…
от Anthropicconfigure
Set up the Discord channel — save the bot token and review access policy. Use when the user pastes a Discord bot token, asks to configure Discord, asks "how…
от Anthropicaccess
Manage iMessage channel access — approve pairings, edit allowlists, set DM/group policy. Use when the user asks to pair, approve someone, check who's allowed…
от Anthropic