Spaces:
Sleeping
Sleeping
Commit ·
fbe8f5e
1
Parent(s): f2d4db5
Add factual-accuracy and sourcing guardrail to content-generation prompts
Browse filesNew pipeline/factual_accuracy.py holds a strict no-fabrication guardrail
(no invented statistics/citations, no merged/guessed sources, no false
authority, prefer omission over confabulation, real captions/alt text only,
flag uncertainty, stay internally consistent). Injected into the two prompts
that actually produce published content: writer._build_system() (the blog
body) and captions.py's new system message (image captions/alt text).
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
- pipeline/captions.py +7 -1
- pipeline/factual_accuracy.py +59 -0
- pipeline/writer.py +2 -0
pipeline/captions.py
CHANGED
|
@@ -9,6 +9,11 @@ from typing import List
|
|
| 9 |
from huggingface_hub import InferenceClient
|
| 10 |
|
| 11 |
from . import config
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 12 |
|
| 13 |
_CAPTION_PROMPT = (
|
| 14 |
"Write a concise, engaging one-sentence caption for this blog illustration. "
|
|
@@ -34,13 +39,14 @@ def caption_images(client: InferenceClient, images: List[dict]) -> List[dict]:
|
|
| 34 |
resp = client.chat.completions.create(
|
| 35 |
model=config.MODEL_VISION,
|
| 36 |
messages=[
|
|
|
|
| 37 |
{
|
| 38 |
"role": "user",
|
| 39 |
"content": [
|
| 40 |
{"type": "text", "text": _CAPTION_PROMPT},
|
| 41 |
{"type": "image_url", "image_url": {"url": _data_uri(Path(path))}},
|
| 42 |
],
|
| 43 |
-
}
|
| 44 |
],
|
| 45 |
max_tokens=80,
|
| 46 |
temperature=0.5,
|
|
|
|
| 9 |
from huggingface_hub import InferenceClient
|
| 10 |
|
| 11 |
from . import config
|
| 12 |
+
from .factual_accuracy import FACTUAL_ACCURACY_GUIDELINES
|
| 13 |
+
|
| 14 |
+
_CAPTION_SYSTEM = (
|
| 15 |
+
"You are writing image captions for a published blog post.\n\n" + FACTUAL_ACCURACY_GUIDELINES
|
| 16 |
+
)
|
| 17 |
|
| 18 |
_CAPTION_PROMPT = (
|
| 19 |
"Write a concise, engaging one-sentence caption for this blog illustration. "
|
|
|
|
| 39 |
resp = client.chat.completions.create(
|
| 40 |
model=config.MODEL_VISION,
|
| 41 |
messages=[
|
| 42 |
+
{"role": "system", "content": _CAPTION_SYSTEM},
|
| 43 |
{
|
| 44 |
"role": "user",
|
| 45 |
"content": [
|
| 46 |
{"type": "text", "text": _CAPTION_PROMPT},
|
| 47 |
{"type": "image_url", "image_url": {"url": _data_uri(Path(path))}},
|
| 48 |
],
|
| 49 |
+
},
|
| 50 |
],
|
| 51 |
max_tokens=80,
|
| 52 |
temperature=0.5,
|
pipeline/factual_accuracy.py
ADDED
|
@@ -0,0 +1,59 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Factual-accuracy and sourcing guardrail injected into every content-generation prompt
|
| 2 |
+
(the blog writer and the image captioner) — anywhere an LLM produces text that ends up in
|
| 3 |
+
the published post.
|
| 4 |
+
"""
|
| 5 |
+
|
| 6 |
+
FACTUAL_ACCURACY_GUIDELINES = """\
|
| 7 |
+
## Factual accuracy and sourcing
|
| 8 |
+
|
| 9 |
+
You are writing published content that readers will trust. Fabricating facts or
|
| 10 |
+
citations is the most serious error you can make — worse than being incomplete,
|
| 11 |
+
vague, or shorter than requested. Follow these rules without exception.
|
| 12 |
+
|
| 13 |
+
- Never invent specifics. Do not state statistics, figures, dates, word counts,
|
| 14 |
+
percentages, technical techniques, or named phenomena unless they are real and
|
| 15 |
+
you are confident they are accurate. A plausible-sounding number or technique is
|
| 16 |
+
not acceptable if you are not sure it is true. When you lack a specific figure,
|
| 17 |
+
describe the point qualitatively ("save files can grow large") rather than
|
| 18 |
+
inventing a precise-sounding claim ("saves exceeded 1MB due to flag tracking").
|
| 19 |
+
|
| 20 |
+
- Cite only what you can verify. Attach a claim to a named source (author, article
|
| 21 |
+
title, book, study, tool, video) ONLY when you are certain both that the source
|
| 22 |
+
exists AND that it actually makes that specific claim. If unsure of either, do
|
| 23 |
+
not name a source: make the point without attribution, or drop it. Never guess
|
| 24 |
+
an author or a title.
|
| 25 |
+
|
| 26 |
+
- Do not merge or confuse sources. Never combine details from two half-remembered
|
| 27 |
+
sources into one citation, attach one source's idea to another's title or author,
|
| 28 |
+
or cite the same work under different names. Keep distinct ideas attributed to
|
| 29 |
+
distinct sources, and only name each if you are certain of it.
|
| 30 |
+
|
| 31 |
+
- No false authority. Do not cite anonymous forum threads, random social-media
|
| 32 |
+
posts, or unnamed videos as authoritative references. If a claim's only basis is
|
| 33 |
+
an unverifiable or low-quality source, omit it or state it plainly as a general
|
| 34 |
+
observation — never dress it up as a cited fact.
|
| 35 |
+
|
| 36 |
+
- Separate established concepts from specific assertions. You may explain
|
| 37 |
+
well-established general concepts in your own words without citation. But any
|
| 38 |
+
specific assertion — a statistic, a claim about what a particular game/product/
|
| 39 |
+
person did, a study's finding, a coined term — must be genuinely true and, if
|
| 40 |
+
attributed, correctly attributed.
|
| 41 |
+
|
| 42 |
+
- Prefer omission over confabulation. If you cannot support a point with something
|
| 43 |
+
real, leave it out. An accurate, slightly less detailed piece beats a detailed
|
| 44 |
+
one containing invented facts. Never fill a gap with a fabricated example, quote,
|
| 45 |
+
statistic, or reference.
|
| 46 |
+
|
| 47 |
+
- Flag genuine uncertainty. When a claim is uncertain or contested, hedge honestly
|
| 48 |
+
("estimates vary," "widely repeated but poorly documented") instead of asserting
|
| 49 |
+
it with false confidence.
|
| 50 |
+
|
| 51 |
+
- Stay internally consistent. Names, dates, numbers, and terminology must agree
|
| 52 |
+
throughout and not contradict each other (e.g., a "published" date must not come
|
| 53 |
+
after its "last updated" date).
|
| 54 |
+
|
| 55 |
+
- Real captions and alt text only. Every caption, alt text, and label must be
|
| 56 |
+
meaningful, correct text. Never output placeholder, garbled, or nonsense strings.
|
| 57 |
+
|
| 58 |
+
When in doubt, leave it out.
|
| 59 |
+
"""
|
pipeline/writer.py
CHANGED
|
@@ -13,6 +13,7 @@ from huggingface_hub import InferenceClient
|
|
| 13 |
|
| 14 |
from . import config, llm
|
| 15 |
from .aeo_guidelines import AEO_GUIDELINES
|
|
|
|
| 16 |
|
| 17 |
# Content-goal directives shape the post's stance and tone. One is selected in the UI.
|
| 18 |
GOAL_GUIDANCE = {
|
|
@@ -66,6 +67,7 @@ def _build_system(target_wordcount: int, content_goal: str) -> str:
|
|
| 66 |
"- End with a short conclusion.\n\n"
|
| 67 |
"AI-citation (AEO) requirements:\n"
|
| 68 |
f"{AEO_GUIDELINES}\n"
|
|
|
|
| 69 |
"Return Markdown only — no preamble, no code fences. Use Markdown pipe tables for "
|
| 70 |
"any tables."
|
| 71 |
)
|
|
|
|
| 13 |
|
| 14 |
from . import config, llm
|
| 15 |
from .aeo_guidelines import AEO_GUIDELINES
|
| 16 |
+
from .factual_accuracy import FACTUAL_ACCURACY_GUIDELINES
|
| 17 |
|
| 18 |
# Content-goal directives shape the post's stance and tone. One is selected in the UI.
|
| 19 |
GOAL_GUIDANCE = {
|
|
|
|
| 67 |
"- End with a short conclusion.\n\n"
|
| 68 |
"AI-citation (AEO) requirements:\n"
|
| 69 |
f"{AEO_GUIDELINES}\n"
|
| 70 |
+
f"{FACTUAL_ACCURACY_GUIDELINES}\n"
|
| 71 |
"Return Markdown only — no preamble, no code fences. Use Markdown pipe tables for "
|
| 72 |
"any tables."
|
| 73 |
)
|