> ## Documentation Index
> Fetch the complete documentation index at: https://docs.compliance.legaltalent.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# Adverse Media Code Examples

> Code snippets for performing adverse media checks on persons, companies, and websites

## Overview

Adverse media checks use AI-powered analysis to search for negative news, criminal records, sanctions, and other risk factors about entities. This guide provides ready-to-use code snippets for integrating adverse media checks into your application.

### Supported Entity Types

| Type      | Description                   | Use Case                |
| --------- | ----------------------------- | ----------------------- |
| `person`  | Individual analysis (default) | Background checks, KYC  |
| `company` | Company/organization analysis | Corporate due diligence |
| `website` | Website/domain reputation     | Merchant verification   |

<CodeGroup>
  ```python theme={null}
  import requests

  BASE_URL = "https://stg.kyc.legaltalent.ai"
  headers = {
      "Authorization": "Bearer YOUR_TOKEN",
      "Content-Type": "application/json"
  }
  ```

  ```javascript theme={null}
  const BASE_URL = 'https://stg.kyc.legaltalent.ai';

  const headers = {
    'Authorization': 'Bearer YOUR_TOKEN',
    'Content-Type': 'application/json'
  };
  ```
</CodeGroup>

## Basic Adverse Media Check

<CodeGroup>
  ```python theme={null}
  # Simple adverse media check
  def check_adverse_media(name, entity_type="person", country=None, age=None, additional_info=None):
      url = f"{BASE_URL}/kyc/adverse-media"
      payload = {
          "name": name,
          "entity_type": entity_type
      }
      
      if country:
          payload["country"] = country
      if age:
          payload["age"] = age
      if additional_info:
          payload["additional_info"] = additional_info
      
      response = requests.post(url, json=payload, headers=headers, timeout=30)
      response.raise_for_status()
      return response.json()

  # Usage
  result = check_adverse_media("John Doe")
  print(f"Risk Score: {result['final_risk_score']}")
  print(f"Decision: {result['decision']}")
  print(f"Summary: {result['summary']}")
  ```

  ```javascript theme={null}
  // Simple adverse media check
  async function checkAdverseMedia(name, entityType = 'person', country, age, additionalInfo) {
    const url = `${BASE_URL}/kyc/adverse-media`;
    const payload = { name, entity_type: entityType };
    
    if (country) payload.country = country;
    if (age) payload.age = age;
    if (additionalInfo) payload.additional_info = additionalInfo;
    
    const response = await fetch(url, {
      method: 'POST',
      headers,
      body: JSON.stringify(payload),
      signal: AbortSignal.timeout(30000)
    });
    
    if (!response.ok) {
      throw new Error(`HTTP error! status: ${response.status}`);
    }
    
    return response.json();
  }

  // Usage
  const result = await checkAdverseMedia('John Doe');
  console.log(`Risk Score: ${result.final_risk_score}`);
  console.log(`Decision: ${result.decision}`);
  console.log(`Summary: ${result.summary}`);
  ```
</CodeGroup>

## Person Check with Context

<CodeGroup>
  ```python theme={null}
  # Check person with additional context for better accuracy
  def check_person_detailed(name, country, age, position=None, company=None):
      url = f"{BASE_URL}/kyc/adverse-media"
      payload = {
          "name": name,
          "entity_type": "person",
          "country": country,
          "age": age
      }
      
      if position and company:
          payload["additional_info"] = f"{position} of {company}"
      elif company:
          payload["additional_info"] = f"Works at {company}"
      
      response = requests.post(url, json=payload, headers=headers, timeout=30)
      response.raise_for_status()
      return response.json()

  # Usage
  result = check_person_detailed(
      "John Doe",
      country="US",
      age=45,
      position="CEO",
      company="Tech Corp"
  )

  # Process results
  if result['decision'] == 'HIGH_RISK':
      print("HIGH RISK - Manual review required")
      for source in result['sources']:
          print(f"- [{source['id']}] {source['title']}: {source['url']}")
  ```

  ```javascript theme={null}
  // Check person with additional context for better accuracy
  async function checkPersonDetailed(name, country, age, position, company) {
    const url = `${BASE_URL}/kyc/adverse-media`;
    const payload = {
      name,
      entity_type: 'person',
      country,
      age
    };
    
    if (position && company) {
      payload.additional_info = `${position} of ${company}`;
    } else if (company) {
      payload.additional_info = `Works at ${company}`;
    }
    
    const response = await fetch(url, {
      method: 'POST',
      headers,
      body: JSON.stringify(payload),
      signal: AbortSignal.timeout(30000)
    });
    
    if (!response.ok) {
      throw new Error(`HTTP error! status: ${response.status}`);
    }
    
    return response.json();
  }

  // Usage
  const result = await checkPersonDetailed(
    'John Doe',
    'US',
    45,
    'CEO',
    'Tech Corp'
  );

  // Process results
  if (result.decision === 'HIGH_RISK') {
    console.log('HIGH RISK - Manual review required');
    result.sources.forEach(source => {
      console.log(`- [${source.id}] ${source.title}: ${source.url}`);
    });
  }
  ```
</CodeGroup>

## Company Analysis

<CodeGroup>
  ```python theme={null}
  # Check company for adverse media
  def check_company(company_name, country=None, additional_info=None):
      url = f"{BASE_URL}/kyc/adverse-media"
      payload = {
          "name": company_name,
          "entity_type": "company"
      }
      
      if country:
          payload["country"] = country
      if additional_info:
          payload["additional_info"] = additional_info
      
      response = requests.post(url, json=payload, headers=headers, timeout=30)
      response.raise_for_status()
      return response.json()

  # Usage
  result = check_company(
      "Tech Corp Inc",
      country="US",
      additional_info="Technology company, founded 2010"
  )

  print(f"Company: {result['entity_name']}")
  print(f"Risk Score: {result['final_risk_score']}")
  print(f"Decision: {result['decision']}")
  print(f"Summary: {result['summary']}")

  if result['sources']:
      print(f"\nFound {len(result['sources'])} adverse sources:")
      for source in result['sources']:
          print(f"- [{source['id']}] {source['title']}")
          print(f"  URL: {source['url']}")
          print(f"  Summary: {source['summary']}")
  ```

  ```javascript theme={null}
  // Check company for adverse media
  async function checkCompany(companyName, country, additionalInfo) {
    const url = `${BASE_URL}/kyc/adverse-media`;
    const payload = {
      name: companyName,
      entity_type: 'company'
    };
    
    if (country) payload.country = country;
    if (additionalInfo) payload.additional_info = additionalInfo;
    
    const response = await fetch(url, {
      method: 'POST',
      headers,
      body: JSON.stringify(payload),
      signal: AbortSignal.timeout(30000)
    });
    
    if (!response.ok) {
      throw new Error(`HTTP error! status: ${response.status}`);
    }
    
    return response.json();
  }

  // Usage
  const result = await checkCompany(
    'Tech Corp Inc',
    'US',
    'Technology company, founded 2010'
  );

  console.log(`Company: ${result.entity_name}`);
  console.log(`Risk Score: ${result.final_risk_score}`);
  console.log(`Decision: ${result.decision}`);
  console.log(`Summary: ${result.summary}`);

  if (result.sources.length > 0) {
    console.log(`\nFound ${result.sources.length} adverse sources:`);
    result.sources.forEach(source => {
      console.log(`- [${source.id}] ${source.title}`);
      console.log(`  URL: ${source.url}`);
      console.log(`  Summary: ${source.summary}`);
    });
  }
  ```
</CodeGroup>

## Website/Domain Analysis

Analyze websites for fraud reports, security issues, blacklists, and consumer complaints.

<CodeGroup>
  ```python theme={null}
  # Check website/domain reputation
  def check_website(url_or_domain, additional_info=None):
      url = f"{BASE_URL}/kyc/adverse-media"
      payload = {
          "name": url_or_domain,
          "entity_type": "website"
      }
      
      if additional_info:
          payload["additional_info"] = additional_info
      
      response = requests.post(url, json=payload, headers=headers, timeout=30)
      response.raise_for_status()
      return response.json()

  # Usage - Check an e-commerce website
  result = check_website(
      "example-shop.com",
      additional_info="E-commerce platform selling electronics"
  )

  print(f"Website: {result['entity_name']}")
  print(f"Risk Score: {result['final_risk_score']}")
  print(f"Decision: {result['decision']}")
  print(f"Summary: {result['summary']}")

  # Check decision
  if result['decision'] in ['MEDIUM_RISK', 'HIGH_RISK']:
      print("\n⚠️ Website requires manual review!")
      for source in result['sources']:
          print(f"\n  [{source['id']}] {source['title']}")
          print(f"  {source['summary']}")
  ```

  ```javascript theme={null}
  // Check website/domain reputation
  async function checkWebsite(urlOrDomain, additionalInfo) {
    const url = `${BASE_URL}/kyc/adverse-media`;
    const payload = {
      name: urlOrDomain,
      entity_type: 'website'
    };
    
    if (additionalInfo) payload.additional_info = additionalInfo;
    
    const response = await fetch(url, {
      method: 'POST',
      headers,
      body: JSON.stringify(payload),
      signal: AbortSignal.timeout(30000)
    });
    
    if (!response.ok) {
      throw new Error(`HTTP error! status: ${response.status}`);
    }
    
    return response.json();
  }

  // Usage - Check an e-commerce website
  const result = await checkWebsite(
    'example-shop.com',
    'E-commerce platform selling electronics'
  );

  console.log(`Website: ${result.entity_name}`);
  console.log(`Risk Score: ${result.final_risk_score}`);
  console.log(`Decision: ${result.decision}`);
  console.log(`Summary: ${result.summary}`);

  // Check decision
  if (['MEDIUM_RISK', 'HIGH_RISK'].includes(result.decision)) {
    console.log('\n⚠️ Website requires manual review!');
    result.sources.forEach(source => {
      console.log(`\n  [${source.id}] ${source.title}`);
      console.log(`  ${source.summary}`);
    });
  }
  ```
</CodeGroup>

## Using Different LLM Providers

<CodeGroup>
  ```python theme={null}
  # Check using OpenAI provider
  def check_adverse_media_openai(name, entity_type="person", country=None, model="gpt-4o-mini"):
      url = f"{BASE_URL}/kyc/adverse-media"
      payload = {
          "name": name,
          "entity_type": entity_type,
          "provider": "openai",
          "model": model
      }
      
      if country:
          payload["country"] = country
      
      response = requests.post(url, json=payload, headers=headers, timeout=30)
      response.raise_for_status()
      return response.json()

  # Usage with OpenAI
  result = check_adverse_media_openai("John Doe", country="US")

  # Default provider (Bedrock with Claude 3.5 Haiku)
  def check_adverse_media_bedrock(name, entity_type="person", country=None):
      url = f"{BASE_URL}/kyc/adverse-media"
      payload = {
          "name": name,
          "entity_type": entity_type
      }
      if country:
          payload["country"] = country
      # provider defaults to "bedrock"
      
      response = requests.post(url, json=payload, headers=headers, timeout=30)
      response.raise_for_status()
      return response.json()

  # Usage with Bedrock (default)
  result = check_adverse_media_bedrock("John Doe", country="US")
  ```

  ```javascript theme={null}
  // Check using OpenAI provider
  async function checkAdverseMediaOpenAI(name, entityType = 'person', country, model = 'gpt-4o-mini') {
    const url = `${BASE_URL}/kyc/adverse-media`;
    const payload = {
      name,
      entity_type: entityType,
      provider: 'openai',
      model
    };
    
    if (country) payload.country = country;
    
    const response = await fetch(url, {
      method: 'POST',
      headers,
      body: JSON.stringify(payload),
      signal: AbortSignal.timeout(30000)
    });
    
    if (!response.ok) {
      throw new Error(`HTTP error! status: ${response.status}`);
    }
    
    return response.json();
  }

  // Usage with OpenAI
  const result = await checkAdverseMediaOpenAI('John Doe', 'person', 'US');

  // Default provider (Bedrock with Claude 3.5 Haiku)
  async function checkAdverseMediaBedrock(name, entityType = 'person', country) {
    const url = `${BASE_URL}/kyc/adverse-media`;
    const payload = { name, entity_type: entityType };
    if (country) payload.country = country;
    // provider defaults to "bedrock"
    
    const response = await fetch(url, {
      method: 'POST',
      headers,
      body: JSON.stringify(payload),
      signal: AbortSignal.timeout(30000)
    });
    
    if (!response.ok) {
      throw new Error(`HTTP error! status: ${response.status}`);
    }
    
    return response.json();
  }

  // Usage with Bedrock (default)
  const result = await checkAdverseMediaBedrock('John Doe', 'person', 'US');
  ```
</CodeGroup>

## Analyzing Results

<CodeGroup>
  ```python theme={null}
  # Comprehensive result analysis
  def analyze_adverse_media_result(result):
      risk_score = result['final_risk_score']
      decision = result['decision']
      summary = result['summary']
      sources = result.get('sources', [])
      
      print(f"Entity: {result['entity_name']} ({result['entity_type']})")
      print(f"Risk Score: {risk_score}/100")
      print(f"Decision: {decision}")
      print(f"\nSummary:\n{summary}\n")
      
      if decision == 'CLEAR':
          print("✅ No adverse media found - entity is clear")
      elif decision == 'LOW_RISK':
          print("ℹ️ Low risk - minor findings, monitor if needed")
      elif decision == 'MEDIUM_RISK':
          print("⚠️ Medium risk - review recommended")
      elif decision == 'HIGH_RISK':
          print("🚨 HIGH RISK - immediate review required")
      
      if sources:
          print(f"\nFound {len(sources)} adverse source(s):")
          for source in sources:
              print(f"\n  [{source['id']}] {source['title']}")
              print(f"  URL: {source['url']}")
              print(f"  Summary: {source['summary']}")
      
      print(f"\nProcessing time: {result.get('processing_time_ms', 0)}ms")
      
      return {
          'risk_score': risk_score,
          'decision': decision,
          'source_count': len(sources),
          'requires_review': decision in ['MEDIUM_RISK', 'HIGH_RISK']
      }

  # Usage
  result = check_adverse_media("John Doe", country="US", age=45)
  analysis = analyze_adverse_media_result(result)

  if analysis['requires_review']:
      print("\n⚠️ Manual compliance review required")
  ```

  ```javascript theme={null}
  // Comprehensive result analysis
  function analyzeAdverseMediaResult(result) {
    const riskScore = result.final_risk_score;
    const decision = result.decision;
    const summary = result.summary;
    const sources = result.sources || [];
    
    console.log(`Entity: ${result.entity_name} (${result.entity_type})`);
    console.log(`Risk Score: ${riskScore}/100`);
    console.log(`Decision: ${decision}`);
    console.log(`\nSummary:\n${summary}\n`);
    
    if (decision === 'CLEAR') {
      console.log('✅ No adverse media found - entity is clear');
    } else if (decision === 'LOW_RISK') {
      console.log('ℹ️ Low risk - minor findings, monitor if needed');
    } else if (decision === 'MEDIUM_RISK') {
      console.log('⚠️ Medium risk - review recommended');
    } else if (decision === 'HIGH_RISK') {
      console.log('🚨 HIGH RISK - immediate review required');
    }
    
    if (sources.length > 0) {
      console.log(`\nFound ${sources.length} adverse source(s):`);
      sources.forEach(source => {
        console.log(`\n  [${source.id}] ${source.title}`);
        console.log(`  URL: ${source.url}`);
        console.log(`  Summary: ${source.summary}`);
      });
    }
    
    console.log(`\nProcessing time: ${result.processing_time_ms || 0}ms`);
    
    return {
      riskScore,
      decision,
      sourceCount: sources.length,
      requiresReview: ['MEDIUM_RISK', 'HIGH_RISK'].includes(decision)
    };
  }

  // Usage
  const result = await checkAdverseMedia('John Doe', 'person', 'US', 45);
  const analysis = analyzeAdverseMediaResult(result);

  if (analysis.requiresReview) {
    console.log('\n⚠️ Manual compliance review required');
  }
  ```
</CodeGroup>

## Risk-Based Filtering

<CodeGroup>
  ```python theme={null}
  # Filter results by risk level
  def filter_by_risk_level(result, min_risk_score=None, risk_decisions=None):
      risk_score = result['final_risk_score']
      decision = result['decision']
      
      if min_risk_score and risk_score < min_risk_score:
          return False
      
      if risk_decisions and decision not in risk_decisions:
          return False
      
      return True

  # Check multiple entities and filter
  def check_multiple_entities(entities, min_risk_score=41):
      results = []
      
      for entity in entities:
          try:
              result = check_adverse_media(
                  entity['name'],
                  entity_type=entity.get('entity_type', 'person'),
                  country=entity.get('country'),
                  age=entity.get('age'),
                  additional_info=entity.get('additional_info')
              )
              
              if filter_by_risk_level(result, min_risk_score=min_risk_score):
                  results.append({
                      'entity': entity['name'],
                      'entity_type': result['entity_type'],
                      'result': result
                  })
          except Exception as e:
              print(f"Error checking {entity['name']}: {e}")
      
      return results

  # Usage
  entities = [
      {"name": "John Doe", "entity_type": "person", "country": "US", "age": 45},
      {"name": "Tech Corp Inc", "entity_type": "company", "country": "US"},
      {"name": "example-shop.com", "entity_type": "website"}
  ]

  flagged_entities = check_multiple_entities(entities, min_risk_score=41)
  print(f"Found {len(flagged_entities)} entities requiring review")
  ```

  ```javascript theme={null}
  // Filter results by risk level
  function filterByRiskLevel(result, minRiskScore, riskDecisions) {
    const riskScore = result.final_risk_score;
    const decision = result.decision;
    
    if (minRiskScore && riskScore < minRiskScore) {
      return false;
    }
    
    if (riskDecisions && !riskDecisions.includes(decision)) {
      return false;
    }
    
    return true;
  }

  // Check multiple entities and filter
  async function checkMultipleEntities(entities, minRiskScore = 41) {
    const results = [];
    
    for (const entity of entities) {
      try {
        const result = await checkAdverseMedia(
          entity.name,
          entity.entity_type || 'person',
          entity.country,
          entity.age,
          entity.additional_info
        );
        
        if (filterByRiskLevel(result, minRiskScore)) {
          results.push({
            entity: entity.name,
            entityType: result.entity_type,
            result
          });
        }
      } catch (error) {
        console.error(`Error checking ${entity.name}:`, error);
      }
    }
    
    return results;
  }

  // Usage
  const entities = [
    { name: 'John Doe', entity_type: 'person', country: 'US', age: 45 },
    { name: 'Tech Corp Inc', entity_type: 'company', country: 'US' },
    { name: 'example-shop.com', entity_type: 'website' }
  ];

  const flaggedEntities = await checkMultipleEntities(entities, 41);
  console.log(`Found ${flaggedEntities.length} entities requiring review`);
  ```
</CodeGroup>

## Merchant Onboarding Workflow

Check both a company and their website before onboarding as a merchant partner.

<CodeGroup>
  ```python theme={null}
  # Complete merchant onboarding check
  def merchant_onboarding_check(company_name, website, country=None):
      results = {
          'company_check': None,
          'website_check': None,
          'overall_decision': 'PENDING'
      }
      
      # 1. Company adverse media check
      company_payload = {
          "name": company_name,
          "entity_type": "company"
      }
      if country:
          company_payload["country"] = country
      
      company_response = requests.post(
          f"{BASE_URL}/kyc/adverse-media",
          json=company_payload,
          headers=headers,
          timeout=30
      )
      results['company_check'] = company_response.json()
      
      # 2. Website reputation check
      website_payload = {
          "name": website,
          "entity_type": "website",
          "additional_info": f"Website for {company_name}"
      }
      
      website_response = requests.post(
          f"{BASE_URL}/kyc/adverse-media",
          json=website_payload,
          headers=headers,
          timeout=30
      )
      results['website_check'] = website_response.json()
      
      # 3. Determine overall decision
      company_risk = results['company_check']['decision']
      website_risk = results['website_check']['decision']
      
      if company_risk == 'HIGH_RISK' or website_risk == 'HIGH_RISK':
          results['overall_decision'] = 'REJECTED'
      elif company_risk == 'MEDIUM_RISK' or website_risk == 'MEDIUM_RISK':
          results['overall_decision'] = 'MANUAL_REVIEW'
      elif company_risk == 'LOW_RISK' or website_risk == 'LOW_RISK':
          results['overall_decision'] = 'REVIEW_RECOMMENDED'
      else:
          results['overall_decision'] = 'APPROVED'
      
      return results

  # Usage
  onboarding = merchant_onboarding_check(
      "Example Shop Inc",
      "example-shop.com",
      country="US"
  )

  print(f"Company Risk: {onboarding['company_check']['decision']}")
  print(f"Website Risk: {onboarding['website_check']['decision']}")
  print(f"Overall Decision: {onboarding['overall_decision']}")

  if onboarding['overall_decision'] != 'APPROVED':
      print("⚠️ Additional review required before merchant onboarding")
  ```

  ```javascript theme={null}
  // Complete merchant onboarding check
  async function merchantOnboardingCheck(companyName, website, country) {
    const results = {
      companyCheck: null,
      websiteCheck: null,
      overallDecision: 'PENDING'
    };
    
    // 1. Company adverse media check
    const companyPayload = {
      name: companyName,
      entity_type: 'company'
    };
    if (country) {
      companyPayload.country = country;
    }
    
    const companyResponse = await fetch(`${BASE_URL}/kyc/adverse-media`, {
      method: 'POST',
      headers,
      body: JSON.stringify(companyPayload),
      signal: AbortSignal.timeout(30000)
    });
    results.companyCheck = await companyResponse.json();
    
    // 2. Website reputation check
    const websitePayload = {
      name: website,
      entity_type: 'website',
      additional_info: `Website for ${companyName}`
    };
    
    const websiteResponse = await fetch(`${BASE_URL}/kyc/adverse-media`, {
      method: 'POST',
      headers,
      body: JSON.stringify(websitePayload),
      signal: AbortSignal.timeout(30000)
    });
    results.websiteCheck = await websiteResponse.json();
    
    // 3. Determine overall decision
    const companyRisk = results.companyCheck.decision;
    const websiteRisk = results.websiteCheck.decision;
    
    if (companyRisk === 'HIGH_RISK' || websiteRisk === 'HIGH_RISK') {
      results.overallDecision = 'REJECTED';
    } else if (companyRisk === 'MEDIUM_RISK' || websiteRisk === 'MEDIUM_RISK') {
      results.overallDecision = 'MANUAL_REVIEW';
    } else if (companyRisk === 'LOW_RISK' || websiteRisk === 'LOW_RISK') {
      results.overallDecision = 'REVIEW_RECOMMENDED';
    } else {
      results.overallDecision = 'APPROVED';
    }
    
    return results;
  }

  // Usage
  const onboarding = await merchantOnboardingCheck(
    'Example Shop Inc',
    'example-shop.com',
    'US'
  );

  console.log(`Company Risk: ${onboarding.companyCheck.decision}`);
  console.log(`Website Risk: ${onboarding.websiteCheck.decision}`);
  console.log(`Overall Decision: ${onboarding.overallDecision}`);

  if (onboarding.overallDecision !== 'APPROVED') {
    console.log('⚠️ Additional review required before merchant onboarding');
  }
  ```
</CodeGroup>

## Customer Onboarding Workflow

Combine watchlist check and adverse media check for comprehensive KYC.

<CodeGroup>
  ```python theme={null}
  # Complete customer onboarding check combining watchlist and adverse media
  def customer_onboarding_check(name, country=None, age=None, document_id=None):
      results = {
          'watchlist_check': None,
          'adverse_media_check': None,
          'overall_decision': 'PENDING'
      }
      
      # 1. Watchlist check
      watchlist_payload = {
          "subject": {"full_name": name}
      }
      if country:
          watchlist_payload["subject"]["nationality"] = country
      if document_id:
          watchlist_payload["subject"]["document_id"] = document_id
      
      watchlist_response = requests.post(
          f"{BASE_URL}/kyc",
          json=watchlist_payload,
          headers=headers,
          timeout=30
      )
      results['watchlist_check'] = watchlist_response.json()
      
      # 2. Adverse media check
      adverse_media_payload = {
          "name": name,
          "entity_type": "person"
      }
      if country:
          adverse_media_payload["country"] = country
      if age:
          adverse_media_payload["age"] = age
      
      adverse_response = requests.post(
          f"{BASE_URL}/kyc/adverse-media",
          json=adverse_media_payload,
          headers=headers,
          timeout=30
      )
      results['adverse_media_check'] = adverse_response.json()
      
      # 3. Determine overall decision
      watchlist_match = results['watchlist_check'].get('result', {}).get('is_match', False)
      adverse_risk = results['adverse_media_check']['decision']
      
      if watchlist_match:
          results['overall_decision'] = 'REJECTED'
      elif adverse_risk == 'HIGH_RISK':
          results['overall_decision'] = 'REVIEW_REQUIRED'
      elif adverse_risk == 'MEDIUM_RISK':
          results['overall_decision'] = 'MANUAL_REVIEW'
      else:
          results['overall_decision'] = 'APPROVED'
      
      return results

  # Usage
  onboarding_result = customer_onboarding_check(
      "John Doe",
      country="US",
      age=45,
      document_id="P123456"
  )

  print(f"Onboarding Decision: {onboarding_result['overall_decision']}")
  if onboarding_result['overall_decision'] != 'APPROVED':
      print("⚠️ Additional review required")
  ```

  ```javascript theme={null}
  // Complete customer onboarding check combining watchlist and adverse media
  async function customerOnboardingCheck(name, country, age, documentId) {
    const results = {
      watchlistCheck: null,
      adverseMediaCheck: null,
      overallDecision: 'PENDING'
    };
    
    // 1. Watchlist check
    const watchlistPayload = {
      subject: { full_name: name }
    };
    if (country) {
      watchlistPayload.subject.nationality = country;
    }
    if (documentId) {
      watchlistPayload.subject.document_id = documentId;
    }
    
    const watchlistResponse = await fetch(`${BASE_URL}/kyc`, {
      method: 'POST',
      headers,
      body: JSON.stringify(watchlistPayload),
      signal: AbortSignal.timeout(30000)
    });
    results.watchlistCheck = await watchlistResponse.json();
    
    // 2. Adverse media check
    const adverseMediaPayload = {
      name,
      entity_type: 'person'
    };
    if (country) adverseMediaPayload.country = country;
    if (age) adverseMediaPayload.age = age;
    
    const adverseResponse = await fetch(`${BASE_URL}/kyc/adverse-media`, {
      method: 'POST',
      headers,
      body: JSON.stringify(adverseMediaPayload),
      signal: AbortSignal.timeout(30000)
    });
    results.adverseMediaCheck = await adverseResponse.json();
    
    // 3. Determine overall decision
    const watchlistMatch = results.watchlistCheck?.result?.is_match || false;
    const adverseRisk = results.adverseMediaCheck.decision;
    
    if (watchlistMatch) {
      results.overallDecision = 'REJECTED';
    } else if (adverseRisk === 'HIGH_RISK') {
      results.overallDecision = 'REVIEW_REQUIRED';
    } else if (adverseRisk === 'MEDIUM_RISK') {
      results.overallDecision = 'MANUAL_REVIEW';
    } else {
      results.overallDecision = 'APPROVED';
    }
    
    return results;
  }

  // Usage
  const onboardingResult = await customerOnboardingCheck(
    'John Doe',
    'US',
    45,
    'P123456'
  );

  console.log(`Onboarding Decision: ${onboardingResult.overallDecision}`);
  if (onboardingResult.overallDecision !== 'APPROVED') {
    console.log('⚠️ Additional review required');
  }
  ```
</CodeGroup>

## Error Handling and Retries

<CodeGroup>
  ```python theme={null}
  import time
  from requests.exceptions import RequestException, Timeout

  def check_adverse_media_with_retry(name, entity_type="person", country=None, max_retries=3, timeout=30):
      url = f"{BASE_URL}/kyc/adverse-media"
      payload = {
          "name": name,
          "entity_type": entity_type
      }
      if country:
          payload["country"] = country
      
      for attempt in range(max_retries):
          try:
              response = requests.post(
                  url,
                  json=payload,
                  headers=headers,
                  timeout=timeout
              )
              response.raise_for_status()
              return response.json()
              
          except Timeout:
              if attempt < max_retries - 1:
                  wait_time = (attempt + 1) * 2  # Exponential backoff
                  print(f"Timeout on attempt {attempt + 1}, retrying in {wait_time}s...")
                  time.sleep(wait_time)
              else:
                  raise Exception("Request timed out after all retries")
          
          except RequestException as e:
              if attempt < max_retries - 1:
                  print(f"Request failed on attempt {attempt + 1}: {e}, retrying...")
                  time.sleep(2)
              else:
                  raise
      
      return None

  # Usage with retry logic
  try:
      result = check_adverse_media_with_retry("John Doe", country="US")
      print(f"Risk Score: {result['final_risk_score']}")
  except Exception as e:
      print(f"Failed to check adverse media: {e}")
  ```

  ```javascript theme={null}
  // Check with retry logic
  async function checkAdverseMediaWithRetry(name, entityType = 'person', country, maxRetries = 3, timeout = 30000) {
    const url = `${BASE_URL}/kyc/adverse-media`;
    const payload = { name, entity_type: entityType };
    if (country) payload.country = country;
    
    for (let attempt = 0; attempt < maxRetries; attempt++) {
      try {
        const controller = new AbortController();
        const timeoutId = setTimeout(() => controller.abort(), timeout);
        
        const response = await fetch(url, {
          method: 'POST',
          headers,
          body: JSON.stringify(payload),
          signal: controller.signal
        });
        
        clearTimeout(timeoutId);
        
        if (!response.ok) {
          throw new Error(`HTTP error! status: ${response.status}`);
        }
        
        return await response.json();
        
      } catch (error) {
        if (attempt < maxRetries - 1) {
          const waitTime = (attempt + 1) * 2000; // Exponential backoff
          console.log(`Attempt ${attempt + 1} failed, retrying in ${waitTime}ms...`);
          await new Promise(resolve => setTimeout(resolve, waitTime));
        } else {
          throw new Error(`Request failed after ${maxRetries} attempts: ${error.message}`);
        }
      }
    }
  }

  // Usage with retry logic
  try {
    const result = await checkAdverseMediaWithRetry('John Doe', 'person', 'US');
    console.log(`Risk Score: ${result.final_risk_score}`);
  } catch (error) {
    console.error(`Failed to check adverse media: ${error.message}`);
  }
  ```
</CodeGroup>

## Risk Score Thresholds

<CodeGroup>
  ```python theme={null}
  # Risk-based decision making
  def get_risk_category(risk_score):
      if risk_score <= 20:
          return "CLEAR"
      elif risk_score <= 40:
          return "LOW_RISK"
      elif risk_score <= 70:
          return "MEDIUM_RISK"
      else:
          return "HIGH_RISK"

  def should_require_review(result, risk_threshold=41):
      risk_score = result['final_risk_score']
      decision = result['decision']
      
      if risk_score >= risk_threshold:
          return True
      
      # Also review if there are any adverse sources
      if len(result.get('sources', [])) > 0:
          return True
      
      return False

  # Automated decision workflow
  def process_adverse_media_check(name, entity_type="person", country=None, auto_approve_threshold=20):
      result = check_adverse_media(name, entity_type=entity_type, country=country)
      
      risk_score = result['final_risk_score']
      decision = result['decision']
      
      if risk_score <= auto_approve_threshold:
          return {
              'status': 'AUTO_APPROVED',
              'risk_score': risk_score,
              'entity_type': result['entity_type'],
              'reason': 'Risk score below threshold'
          }
      elif should_require_review(result):
          return {
              'status': 'REVIEW_REQUIRED',
              'risk_score': risk_score,
              'decision': decision,
              'entity_type': result['entity_type'],
              'sources': result.get('sources', []),
              'reason': f'Risk score {risk_score} exceeds threshold'
          }
      else:
          return {
              'status': 'MANUAL_REVIEW',
              'risk_score': risk_score,
              'entity_type': result['entity_type'],
              'reason': 'Standard review process'
          }
  ```

  ```javascript theme={null}
  // Risk-based decision making
  function getRiskCategory(riskScore) {
    if (riskScore <= 20) return 'CLEAR';
    if (riskScore <= 40) return 'LOW_RISK';
    if (riskScore <= 70) return 'MEDIUM_RISK';
    return 'HIGH_RISK';
  }

  function shouldRequireReview(result, riskThreshold = 41) {
    const riskScore = result.final_risk_score;
    
    if (riskScore >= riskThreshold) {
      return true;
    }
    
    // Also review if there are any adverse sources
    if ((result.sources || []).length > 0) {
      return true;
    }
    
    return false;
  }

  // Automated decision workflow
  async function processAdverseMediaCheck(name, entityType = 'person', country, autoApproveThreshold = 20) {
    const result = await checkAdverseMedia(name, entityType, country);
    
    const riskScore = result.final_risk_score;
    const decision = result.decision;
    
    if (riskScore <= autoApproveThreshold) {
      return {
        status: 'AUTO_APPROVED',
        riskScore,
        entityType: result.entity_type,
        reason: 'Risk score below threshold'
      };
    } else if (shouldRequireReview(result)) {
      return {
        status: 'REVIEW_REQUIRED',
        riskScore,
        decision,
        entityType: result.entity_type,
        sources: result.sources || [],
        reason: `Risk score ${riskScore} exceeds threshold`
      };
    } else {
      return {
        status: 'MANUAL_REVIEW',
        riskScore,
        entityType: result.entity_type,
        reason: 'Standard review process'
      };
    }
  }
  ```
</CodeGroup>

## Related References

* [Adverse Media API Reference](/api-reference/adverse-media) - Complete API documentation
* [List Check API](/api-reference/list-check) - Traditional watchlist checks
* [Validate Person or Company](/validate-person-entity) - Entity validation guide
* [Watchlists Guide](/watchlists-guide) - Continuous monitoring with watchlists
