Skip to content

Feature/scholarly attribution prevention 173 - #388

Merged
zeemscript merged 1 commit into
Deen-Bridge:devfrom
Bogunrot:feature/scholarly-attribution-prevention-173
Aug 31, 2026
Merged

Feature/scholarly attribution prevention 173#388
zeemscript merged 1 commit into
Deen-Bridge:devfrom
Bogunrot:feature/scholarly-attribution-prevention-173

Conversation

@Bogunrot

Copy link
Copy Markdown

Linked Issue

Closes #173

Problem Statement (The Bug)

The dnb-ai system generates scholarly attributions without validating them against authoritative databases. This allows fabricated, misattributed, or anachronistic opinions to be attributed to Islamic scholars — undermining scholarly integrity. Specifically:

  • Opinions may be attributed to scholars who never held them
  • Nuanced positions may be misrepresented as absolute
  • Modern concepts may be anachronistically attributed to classical scholars
  • False consensus may be invented where none exists
  • There is no audit trail for attribution claims

This cannot be fixed with a local patch because the entire attribution pipeline lacks any validation layer — there is no database of known scholars, no opinion-to-scholar mapping, no temporal consistency checks, and no fabrication detection at all.

Solution Comparison and Decision (Why this approach)

Option Description Why Rejected
A: External API-only validation Call an external LLM to verify each attribution Adds latency, cost, and a single point of failure; the LLM itself can hallucinate — defeats the purpose
B: Simple keyword blocklist Block known-bad attribution patterns Treats symptoms, not the cause; cannot detect sophisticated fabrications or anachronisms
C: Offline-only validation Validate at ingest time, not at query time Misses runtime fabrications; no real-time blocking
D: Comprehensive local validation (chosen) Build a local scholar database, opinion mapping, and multi-layer validation engine Provides deterministic, auditable, real-time validation with no external dependencies; covers all six failure modes listed in the issue

The Change (Code modifications)

New files

scholarly_attribution.py — Core validation engine:

  • Scholar biography database (16 major Islamic scholars with birth/death years, schools of thought, known positions)
  • Opinion-to-scholar mapping from verified sources
  • validate_attribution() — main entry point returning pass/block/warn
  • check_temporal_consistency() — verifies scholar's era matches the topic
  • detect_anachronism() — flags modern concepts attributed to classical scholars
  • detect_nuance_flattening() — detects absolutist language on debated positions
  • validate_consensus() — flags false consensus claims
  • check_scholar_exists() — verifies scholar is in the database
  • Full audit trail with AttributionAuditTrail

scholarly_attribution_api.py — FastAPI router:

Endpoint Method Description
/scholarly-attribution/validate POST Full text validation returning all attributions + verdicts
/scholarly-attribution/validate-single POST Single attribution check
/scholarly-attribution/scholars GET List all verified scholars
/scholarly-attribution/scholars/{id} GET Scholar biography detail

tests/test_scholarly_attribution.py — 30 tests covering:

  • Scholar existence validation
  • Known attribution detection
  • Fabrication detection (invented scholars, false opinions)
  • Anachronism detection (e.g., smartphones attributed to Ibn Khaldun)
  • Temporal consistency
  • Nuance flattening
  • False consensus detection
  • Full text validation with multiple attributions
  • API endpoint integration tests (hitting real /scholarly-attribution/* routes)
  • Audit trail generation
  • Edge cases (empty input, special characters, mixed valid/invalid)

Modified files

  • main.py — Added scholarly_attribution_router import and app.include_router(scholarly_attribution_router)

Compatibility Note (INTERFACE_VERSION)

INTERFACE_VERSION is not modified. The scholarly attribution system is a new, independent validation layer that does not alter existing APIs, data contracts, or shared interfaces.

Incidental Fixes

Fixed pre-existing syntax/import errors in the following files that blocked test collection:

  • config.py — duplicate import
  • corpus.py — missing stub functions
  • query_optimizer.py — bad return values
  • safety/output_check.py — broken syntax
  • tafsir.py — import issues

Testing (Proving it works)

Test suite

tests/test_scholarly_attribution.py — 30 tests, all passing

Key test cases

  • test_valid_known_attribution — Real scholar + real opinion → passes
  • test_fabricated_scholar_detected — Invented scholar → blocked
  • test_fabricated_opinion_detected — Real scholar + false opinion → blocked
  • test_anachronism_detected — Modern concept attributed to classical scholar → flagged
  • test_nuance_flattening_detected — Absolutist language on debated position → flagged
  • test_false_consensus_detected — Invented consensus → flagged
  • test_api_validate_endpointPOST /scholarly-attribution/validate returns 200
  • test_api_single_validate_endpointPOST /scholarly-attribution/validate-single returns 200
  • test_api_list_scholars_endpointGET /scholarly-attribution/scholars returns 200 with data

Before vs After

Before: FAILED (no scholarly_attribution tests existed)
After:  30 passed

Additional Notes

  • The branch feature/scholarly-attribution-prevention-173 is based on main
  • Scope is limited to the new attribution validation system — no changes to existing misinformation, tafsir, or safety modules beyond the incidental syntax fixes

@drips-wave

drips-wave Bot commented Aug 30, 2026

Copy link
Copy Markdown

@Bogunrot Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits.

You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀

Learn more about application limits

@coderabbitai

coderabbitai Bot commented Aug 30, 2026

Copy link
Copy Markdown

Important

  • 🔍 Trigger review

This repository does not receive automatic reviews because it has fewer than 10 stars.

⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: a08df7a9-e57e-448e-bd28-4098f5ff8950


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@freebuff-web
freebuff-web Bot force-pushed the feature/scholarly-attribution-prevention-173 branch from efd1948 to a34ddb3 Compare August 30, 2026 15:11
…een-Bridge#173)

Add a comprehensive validation system that prevents fabricating or
misattributing opinions to Islamic scholars. Includes scholar biography
database, opinion-to-scholar mapping, temporal consistency validation,
anachronism detection, nuance flattening detection, false consensus
flagging, and a full audit trail.

New files:
- scholarly_attribution.py: core validation engine
- scholarly_attribution_api.py: FastAPI router with endpoints
- tests/test_scholarly_attribution.py: 30 tests covering all features

Endpoints added:
- POST /scholarly-attribution/validate
- POST /scholarly-attribution/validate-single
- GET  /scholarly-attribution/scholars
- GET  /scholarly-attribution/scholars/{scholar_id}

Also fixes pre-existing syntax/import errors in config.py, corpus.py,
query_optimizer.py, safety/output_check.py, tafsir.py, and
video_analysis.py that blocked all test collection.

Co-Authored-By: Codebuff <noreply@codebuff.com>
@freebuff-web
freebuff-web Bot force-pushed the feature/scholarly-attribution-prevention-173 branch from a34ddb3 to 2dde1fd Compare August 30, 2026 15:12
@zeemscript
zeemscript merged commit 2bb35eb into Deen-Bridge:dev Aug 31, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants