Tutorial

How to Build a Shariah-Compliant Investing Research Agent

Open source AI research agent for halal finance. Replace Brave + Tavily + Exa + Perplexity with one API plus a fundamentals layer.

An r/HalalInvestor post released Yassir v0.1.0 — an OSS Shariah-compliant research agent. Its stack used four web-search vendors plus HalalTerminal. This tutorial consolidates the web layer to Scavio while keeping fundamentals on a specialist API.

Prerequisites

  • Python 3.10+ or TypeScript / Bun
  • Scavio API key
  • Polygon.io free tier

Walkthrough

Step 1: Replace the four-vendor web fallback chain

One Scavio call covers what Brave + Tavily + Exa + Perplexity did.

Python
import requests, os
API_KEY = os.environ['SCAVIO_API_KEY']

def web(q):
    return requests.post('https://api.scavio.dev/api/v1/search',
        headers={'x-api-key': API_KEY}, json={'query': q}).json()

Step 2: Reddit retail-sentiment layer

r/halalinvesting, r/wallstreetbets surface sentiment shifts.

Python
def reddit(q):
    return requests.post('https://api.scavio.dev/api/v1/reddit/search',
        headers={'x-api-key': API_KEY}, json={'query': q}).json()

Step 3: Polygon for fundamentals

Free tier delayed but acceptable for research.

Python
from polygon import RESTClient
client = RESTClient(api_key=os.environ['POLYGON_API_KEY'])

def fundamentals(ticker):
    return client.get_ticker_details(ticker)

Step 4: Shariah filter in the agent prompt

The LLM applies riba / gharar / haram filters.

Text
RULES = '''
Reject if: interest-bearing debt > 33% of market cap; alcohol/gambling/conventional finance revenue > 5%.
Flag for purification if: small interest income.
'''

Step 5: Compose sourced answer

Three surfaces + fundamentals + Shariah filter.

Python
def research(ticker):
    return {'web': web(f'{ticker} 2026 financials'), 'reddit': reddit(ticker), 'fundamentals': fundamentals(ticker)}

Python Example

Python
# Per-question cost: 2-3 Scavio calls + 1 Polygon call. Total ~$0.013 + Polygon (free tier).

JavaScript Example

JavaScript
// TypeScript / Bun version uses the same endpoints.

Expected Output

JSON
Per-ticker research brief: web summary, retail sentiment, fundamentals, Shariah-compliance verdict.

Related Tutorials

Frequently Asked Questions

Most developers complete this tutorial in 15 to 30 minutes. You will need a Scavio API key (free tier works) and a working Python or JavaScript environment.

Python 3.10+ or TypeScript / Bun. Scavio API key. Polygon.io free tier. A Scavio API key gives you 500 free credits per month.

Yes. The free tier includes 500 credits per month, which is more than enough to complete this tutorial and prototype a working solution.

Scavio has a native LangChain package (langchain-scavio), an MCP server, and a plain REST API that works with any HTTP client. This tutorial uses the raw REST API, but you can adapt to your framework of choice.

Start Building

Open source AI research agent for halal finance. Replace Brave + Tavily + Exa + Perplexity with one API plus a fundamentals layer.