Skip to main content
All use casesUse Case

Search contracts and case files with retrieval-grounded answers.

Legal AI tools live or die on citation accuracy — answers need to be traceable back to the source clause or document. The kit's RAG pipeline returns source references alongside every answer, which is the baseline requirement for this use case.

FastAPIpgvectorOpenAIPostgreSQLCeleryStripe

The usual pain points

  • Returning answers that cite the specific clause or document they came from
  • Restricting access to documents by matter, client, or team
  • Ingesting large volumes of contracts or filings without blocking
  • Billing usage per matter or per seat for internal chargebacks

How the kit solves them

  • RAG query responses include source chunk references, not just a bare answer
  • Per-API-key access control scopes which collections (matters) a key can query
  • Celery-based ingestion handles large PDF batches without blocking the API
  • Stripe metering supports per-matter or per-seat billing configurations

Example implementation

main.py
@router.post("/v1/legal/query")
@require_api_key(tier=["legal"])
async def query_matter(body: MatterQueryRequest, key: APIKey = Depends(get_api_key)):
    await verify_collection_access(key, body.matter_id)
    result = await rag.query(question=body.question, collection=body.matter_id, top_k=5)
    return {"answer": result.text, "citations": result.sources}

Ready to build your ai legal assistant backend?

FastAPI AI Kit ships with everything shown above, pre-configured and production-ready. Clone the repo and start building in minutes.

Ready to ship your AI backend this weekend?

Join developers who skipped weeks of boilerplate and went straight to building.

Read the docs
No subscriptions · One-time payment · Lifetime updates