# OSHA Violation Risk & Time-Series (`fried_calamaries/osha-violation-risk`) Actor

Turn any US employer's OSHA inspection history into a risk score, repeat-offender flag, and violation time-series â€” severity-weighted, auditable, and tracked over time.

- **URL**: https://apify.com/fried\_calamaries/osha-violation-risk.md
- **Developed by:** [ByteMe](https://apify.com/fried_calamaries) (community)
- **Categories:** Business
- **Stats:** 2 total users, 1 monthly users, 100.0% runs succeeded, 0 bookmarks
- **User rating**: No ratings yet

## Pricing

$0.02 / employer risk report

This Actor is paid per event. You are not charged for the Apify platform usage, but only a fixed price for specific events.

Learn more: https://docs.apify.com/platform/actors/running/actors-in-store#pay-per-event

## What's an Apify Actor?

Actors are a software tools running on the Apify platform, for all kinds of web data extraction and automation use cases.
In Batch mode, an Actor accepts a well-defined JSON input, performs an action which can take anything from a few seconds to a few hours,
and optionally produces a well-defined JSON output, datasets with results, or files in key-value store.
In Standby mode, an Actor provides a web server which can be used as a website, API, or an MCP server.
Actors are written with capital "A".

## How to integrate an Actor?

If asked about integration, you help developers integrate Actors into their projects.
You adapt to their stack and deliver integrations that are safe, well-documented, and production-ready.
The best way to integrate Actors is as follows.

In JavaScript/TypeScript projects, use official [JavaScript/TypeScript client](https://docs.apify.com/api/client/js.md):

```bash
npm install apify-client
```

In Python projects, use official [Python client library](https://docs.apify.com/api/client/python.md):

```bash
pip install apify-client
```

In shell scripts, use [Apify CLI](https://docs.apify.com/cli/docs.md):

````bash
# MacOS / Linux
curl -fsSL https://apify.com/install-cli.sh | bash
# Windows
irm https://apify.com/install-cli.ps1 | iex
```bash

In AI frameworks, you might use the [Apify MCP server](https://docs.apify.com/platform/integrations/mcp.md).

If your project is in a different language, use the [REST API](https://docs.apify.com/api/v2.md).

For usage examples, see the [API](#api) section below.

For more details, see Apify documentation as [Markdown index](https://docs.apify.com/llms.txt) and [Markdown full-text](https://docs.apify.com/llms-full.txt).


# README

## OSHA Violation Risk & Time-Series

### Pain points

- OSHA's IMIS database has 5M+ inspections and 13M+ violations, but no risk score — you read raw citations by hand.
- Underwriters and due-diligence teams need a defensible safety-risk signal per employer, not a pile of citation rows.
- Spotting repeat offenders and whether violations are trending up requires manually stitching years of inspections together.

### What we solve

- Pull every OSHA inspection for an employer and its citations (gravity, penalties, standards, dates).
- Compute a deterministic, auditable 0-100 risk score weighted by violation severity and recency.
- Flag repeat offenders, chart violations over time, and label the trend (rising / flat / falling).
- Run on a schedule to catch new inspections, new violations, and risk-score changes.

### Summary

Give it a US employer name and get back an **OSHA safety-risk report**: every inspection and citation (gravity, penalty, standard, dates) rolled up into a **deterministic, auditable risk score** (0-100, severity-weighted and recency-decayed), a **repeat-offender** flag, total penalties, and a **violations-over-time** series with a rising/flat/falling trend. Built on OSHA's public IMIS data — no scraping fragility, no anti-bot. Run it on a schedule and it also reports **what changed** since last time: new inspections, new violations, and risk-score movement. Built for safety consultants, insurance underwriters, and supply-chain due-diligence.

### Who it's for

- Insurance underwriters pricing workers'-comp and liability risk
- Safety consultants and EHS teams benchmarking employers
- Supply-chain and vendor due-diligence teams
- Investors and M&A diligence screening for safety liabilities

### How to use

Set the input, run the actor, and collect results from the run's dataset (export to JSON/CSV/Excel, or pull via the Apify API). Example input:

```json
{
  "employers": [
    "Dollar General"
  ],
  "maxInspectionsPerEmployer": 25,
  "compareToPrevious": true
}
````

See **Inputs** below for every available field.

### What you get

One row per record:

| Field | Description |
|---|---|
| `query` | The employer name you searched |
| `risk_score` | Deterministic 0-100 severity-weighted, recency-decayed risk score |
| `risk_band` | low / medium / high |
| `repeat_offender` | True if any Repeat-gravity violations |
| `trend` | rising / flat / falling (recent vs prior 2-year windows) |
| `by_gravity` | Violation counts by OSHA gravity (willful/repeat/serious/other) |
| `total_current_penalty` | Sum of current penalties (USD) |
| `violation_time_series` | Violations + penalty per year |
| `inspection_count / violation_count` | Totals analyzed |
| `inspections` | Per-inspection detail including each citation |
| `new_inspections / new_violations / risk_score_delta` | What changed since the previous run (monitoring) |
| `source_url` | The OSHA search this report came from |

Sample:

```json
{
  "query": "Dollar General",
  "state": null,
  "establishments": [
    "Dollar General Store 12345"
  ],
  "inspection_count": 2,
  "violation_count": 2,
  "by_gravity": {
    "serious": 2
  },
  "total_current_penalty": 14000,
  "total_initial_penalty": 14000,
  "risk_score": 21,
  "risk_band": "medium",
  "repeat_offender": false,
  "trend": "falling",
  "violation_time_series": [
    {
      "year": 2024,
      "violations": 2,
      "penalty": 14000
    }
  ],
  "first_seen": false,
  "new_inspections": 0,
  "new_violations": 0,
  "risk_score_delta": 0,
  "source_url": "https://www.osha.gov/ords/imis/establishment.search?establishment=Dollar+General&state=all"
}
```

### Inputs

| Field | Required | Type | Default | Description |
|---|---|---|---|---|
| `employers` | yes | array | `["Dollar General"]` | US employer / company names to analyze (e.g. 'Dollar General'). One risk report per name, aggregating all of that employer's OSHA inspections. |
| `state` | no | string | — | Optional two-letter state code (e.g. 'TX') to limit inspections to that state. Leave empty for nationwide. |
| `maxInspectionsPerEmployer` | no | integer | `25` | Cap on inspections pulled per employer (most-recent first). Each inspection is one detail fetch; higher = more complete history, slower run. |
| `compareToPrevious` | no | boolean | `true` | When on (default), diff each employer against the previous run and report what changed — new inspections, new violations, risk-score delta. Run on a schedule to track employers over time. |
| `proxyConfiguration` | no | object | `{"useApifyProxy": false}` | Optional. OSHA's public site is reachable directly; a proxy is rarely needed. |

### Pricing (Pay Per Event)

You pay per result (`dataset-item`) — **no charge for empty runs**. Example: **100 employer risk reports** at *$0.02/result* ≈ **$2.00**.

One charge per employer risk report produced. Employers with no OSHA inspections found are returned empty and not charged. Apify platform usage (compute) is billed separately per your plan.

### Use cases

- Underwriting risk signal — get a defensible, auditable safety-risk score per employer.
- Vendor due diligence — screen suppliers for repeat OSHA violations before contracting.
- Safety benchmarking — compare employers' violation history and penalty totals.
- Monitoring — run weekly to catch new inspections and rising risk on watched employers.

### Why this actor

- A risk score, not raw citations — severity-weighted, recency-decayed, and fully auditable (the formula is documented).
- Repeat-offender flag, penalty totals, and a violations-over-time trend in one report.
- Built on OSHA's public data — no anti-bot fragility — and tracks what changes over time.

### Limitations & updates

Covers OSHA federal and state-plan inspection data exposed in the public IMIS establishment search. Establishment names in OSHA data are per-inspection and inconsistent, so reports aggregate at the employer-query level (use the state filter to narrow). The risk score reflects recorded violations only — not unreported hazards — and is a relative signal, not a regulatory determination.

### FAQ

**Where does the data come from?**

OSHA's public IMIS enforcement database (inspections + citations). Public data, no login required.

**How is the risk score calculated?**

A deterministic formula: violations weighted by OSHA gravity (Willful > Repeat > Serious > Other) and decayed by recency, scaled to 0-100. It's reproducible and auditable — the same history always yields the same score.

**What counts as a repeat offender?**

Any employer with one or more citations OSHA classified as 'Repeat' gravity.

**Can I limit to one state?**

Yes — pass a two-letter state code to restrict the inspections analyzed; leave it empty for nationwide.

**How am I charged?**

Per employer risk report produced. Employers with no inspections found are returned empty and not charged.

**Can it track changes over time?**

Yes — run on a schedule and it reports new inspections, new violations, and risk-score movement since the previous run.

# Actor input Schema

## `employers` (type: `array`):

US employer / company names to analyze (e.g. 'Dollar General'). One risk report per name, aggregating all of that employer's OSHA inspections.

## `state` (type: `string`):

Optional two-letter state code (e.g. 'TX') to limit inspections to that state. Leave empty for nationwide.

## `maxInspectionsPerEmployer` (type: `integer`):

Cap on inspections pulled per employer (most-recent first). Each inspection is one detail fetch; higher = more complete history, slower run.

## `compareToPrevious` (type: `boolean`):

When on (default), diff each employer against the previous run and report what changed — new inspections, new violations, risk-score delta. Run on a schedule to track employers over time.

## `proxyConfiguration` (type: `object`):

Optional. OSHA's public site is reachable directly; a proxy is rarely needed.

## Actor input object example

```json
{
  "employers": [
    "Dollar General",
    "Dollar Tree"
  ],
  "maxInspectionsPerEmployer": 25,
  "compareToPrevious": true,
  "proxyConfiguration": {
    "useApifyProxy": false
  }
}
```

# Actor output Schema

## `reports` (type: `string`):

Per-employer OSHA risk report: risk score/band, repeat-offender flag, trend, penalties, and violations over time.

# API

You can run this Actor programmatically using our API. Below are code examples in JavaScript, Python, and CLI, as well as the OpenAPI specification and MCP server setup.

## JavaScript example

```javascript
import { ApifyClient } from 'apify-client';

// Initialize the ApifyClient with your Apify API token
// Replace the '<YOUR_API_TOKEN>' with your token
const client = new ApifyClient({
    token: '<YOUR_API_TOKEN>',
});

// Prepare Actor input
const input = {
    "employers": [
        "Dollar General"
    ]
};

// Run the Actor and wait for it to finish
const run = await client.actor("fried_calamaries/osha-violation-risk").call(input);

// Fetch and print Actor results from the run's dataset (if any)
console.log('Results from dataset');
console.log(`💾 Check your data here: https://console.apify.com/storage/datasets/${run.defaultDatasetId}`);
const { items } = await client.dataset(run.defaultDatasetId).listItems();
items.forEach((item) => {
    console.dir(item);
});

// 📚 Want to learn more 📖? Go to → https://docs.apify.com/api/client/js/docs

```

## Python example

```python
from apify_client import ApifyClient

# Initialize the ApifyClient with your Apify API token
# Replace '<YOUR_API_TOKEN>' with your token.
client = ApifyClient("<YOUR_API_TOKEN>")

# Prepare the Actor input
run_input = { "employers": ["Dollar General"] }

# Run the Actor and wait for it to finish
run = client.actor("fried_calamaries/osha-violation-risk").call(run_input=run_input)

# Fetch and print Actor results from the run's dataset (if there are any)
print("💾 Check your data here: https://console.apify.com/storage/datasets/" + run["defaultDatasetId"])
for item in client.dataset(run["defaultDatasetId"]).iterate_items():
    print(item)

# 📚 Want to learn more 📖? Go to → https://docs.apify.com/api/client/python/docs/quick-start

```

## CLI example

```bash
echo '{
  "employers": [
    "Dollar General"
  ]
}' |
apify call fried_calamaries/osha-violation-risk --silent --output-dataset

```

## MCP server setup

```json
{
    "mcpServers": {
        "apify": {
            "command": "npx",
            "args": [
                "mcp-remote",
                "https://mcp.apify.com/?tools=fried_calamaries/osha-violation-risk",
                "--header",
                "Authorization: Bearer <YOUR_API_TOKEN>"
            ]
        }
    }
}

```

## OpenAPI specification

```json
{
    "openapi": "3.0.1",
    "info": {
        "title": "OSHA Violation Risk & Time-Series",
        "description": "Turn any US employer's OSHA inspection history into a risk score, repeat-offender flag, and violation time-series â€” severity-weighted, auditable, and tracked over time.",
        "version": "0.1",
        "x-build-id": "B2vdd576Bq2ae9zs8"
    },
    "servers": [
        {
            "url": "https://api.apify.com/v2"
        }
    ],
    "paths": {
        "/acts/fried_calamaries~osha-violation-risk/run-sync-get-dataset-items": {
            "post": {
                "operationId": "run-sync-get-dataset-items-fried_calamaries-osha-violation-risk",
                "x-openai-isConsequential": false,
                "summary": "Executes an Actor, waits for its completion, and returns Actor's dataset items in response.",
                "tags": [
                    "Run Actor"
                ],
                "requestBody": {
                    "required": true,
                    "content": {
                        "application/json": {
                            "schema": {
                                "$ref": "#/components/schemas/inputSchema"
                            }
                        }
                    }
                },
                "parameters": [
                    {
                        "name": "token",
                        "in": "query",
                        "required": true,
                        "schema": {
                            "type": "string"
                        },
                        "description": "Enter your Apify token here"
                    }
                ],
                "responses": {
                    "200": {
                        "description": "OK"
                    }
                }
            }
        },
        "/acts/fried_calamaries~osha-violation-risk/runs": {
            "post": {
                "operationId": "runs-sync-fried_calamaries-osha-violation-risk",
                "x-openai-isConsequential": false,
                "summary": "Executes an Actor and returns information about the initiated run in response.",
                "tags": [
                    "Run Actor"
                ],
                "requestBody": {
                    "required": true,
                    "content": {
                        "application/json": {
                            "schema": {
                                "$ref": "#/components/schemas/inputSchema"
                            }
                        }
                    }
                },
                "parameters": [
                    {
                        "name": "token",
                        "in": "query",
                        "required": true,
                        "schema": {
                            "type": "string"
                        },
                        "description": "Enter your Apify token here"
                    }
                ],
                "responses": {
                    "200": {
                        "description": "OK",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/runsResponseSchema"
                                }
                            }
                        }
                    }
                }
            }
        },
        "/acts/fried_calamaries~osha-violation-risk/run-sync": {
            "post": {
                "operationId": "run-sync-fried_calamaries-osha-violation-risk",
                "x-openai-isConsequential": false,
                "summary": "Executes an Actor, waits for completion, and returns the OUTPUT from Key-value store in response.",
                "tags": [
                    "Run Actor"
                ],
                "requestBody": {
                    "required": true,
                    "content": {
                        "application/json": {
                            "schema": {
                                "$ref": "#/components/schemas/inputSchema"
                            }
                        }
                    }
                },
                "parameters": [
                    {
                        "name": "token",
                        "in": "query",
                        "required": true,
                        "schema": {
                            "type": "string"
                        },
                        "description": "Enter your Apify token here"
                    }
                ],
                "responses": {
                    "200": {
                        "description": "OK"
                    }
                }
            }
        }
    },
    "components": {
        "schemas": {
            "inputSchema": {
                "type": "object",
                "required": [
                    "employers"
                ],
                "properties": {
                    "employers": {
                        "title": "Employers",
                        "type": "array",
                        "description": "US employer / company names to analyze (e.g. 'Dollar General'). One risk report per name, aggregating all of that employer's OSHA inspections.",
                        "items": {
                            "type": "string"
                        }
                    },
                    "state": {
                        "title": "State filter",
                        "type": "string",
                        "description": "Optional two-letter state code (e.g. 'TX') to limit inspections to that state. Leave empty for nationwide."
                    },
                    "maxInspectionsPerEmployer": {
                        "title": "Max inspections per employer",
                        "minimum": 1,
                        "maximum": 200,
                        "type": "integer",
                        "description": "Cap on inspections pulled per employer (most-recent first). Each inspection is one detail fetch; higher = more complete history, slower run.",
                        "default": 25
                    },
                    "compareToPrevious": {
                        "title": "Monitor changes",
                        "type": "boolean",
                        "description": "When on (default), diff each employer against the previous run and report what changed — new inspections, new violations, risk-score delta. Run on a schedule to track employers over time.",
                        "default": true
                    },
                    "proxyConfiguration": {
                        "title": "Proxy configuration",
                        "type": "object",
                        "description": "Optional. OSHA's public site is reachable directly; a proxy is rarely needed.",
                        "default": {
                            "useApifyProxy": false
                        }
                    }
                }
            },
            "runsResponseSchema": {
                "type": "object",
                "properties": {
                    "data": {
                        "type": "object",
                        "properties": {
                            "id": {
                                "type": "string"
                            },
                            "actId": {
                                "type": "string"
                            },
                            "userId": {
                                "type": "string"
                            },
                            "startedAt": {
                                "type": "string",
                                "format": "date-time",
                                "example": "2025-01-08T00:00:00.000Z"
                            },
                            "finishedAt": {
                                "type": "string",
                                "format": "date-time",
                                "example": "2025-01-08T00:00:00.000Z"
                            },
                            "status": {
                                "type": "string",
                                "example": "READY"
                            },
                            "meta": {
                                "type": "object",
                                "properties": {
                                    "origin": {
                                        "type": "string",
                                        "example": "API"
                                    },
                                    "userAgent": {
                                        "type": "string"
                                    }
                                }
                            },
                            "stats": {
                                "type": "object",
                                "properties": {
                                    "inputBodyLen": {
                                        "type": "integer",
                                        "example": 2000
                                    },
                                    "rebootCount": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "restartCount": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "resurrectCount": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "computeUnits": {
                                        "type": "integer",
                                        "example": 0
                                    }
                                }
                            },
                            "options": {
                                "type": "object",
                                "properties": {
                                    "build": {
                                        "type": "string",
                                        "example": "latest"
                                    },
                                    "timeoutSecs": {
                                        "type": "integer",
                                        "example": 300
                                    },
                                    "memoryMbytes": {
                                        "type": "integer",
                                        "example": 1024
                                    },
                                    "diskMbytes": {
                                        "type": "integer",
                                        "example": 2048
                                    }
                                }
                            },
                            "buildId": {
                                "type": "string"
                            },
                            "defaultKeyValueStoreId": {
                                "type": "string"
                            },
                            "defaultDatasetId": {
                                "type": "string"
                            },
                            "defaultRequestQueueId": {
                                "type": "string"
                            },
                            "buildNumber": {
                                "type": "string",
                                "example": "1.0.0"
                            },
                            "containerUrl": {
                                "type": "string"
                            },
                            "usage": {
                                "type": "object",
                                "properties": {
                                    "ACTOR_COMPUTE_UNITS": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "DATASET_READS": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "DATASET_WRITES": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "KEY_VALUE_STORE_READS": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "KEY_VALUE_STORE_WRITES": {
                                        "type": "integer",
                                        "example": 1
                                    },
                                    "KEY_VALUE_STORE_LISTS": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "REQUEST_QUEUE_READS": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "REQUEST_QUEUE_WRITES": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "DATA_TRANSFER_INTERNAL_GBYTES": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "DATA_TRANSFER_EXTERNAL_GBYTES": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "PROXY_RESIDENTIAL_TRANSFER_GBYTES": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "PROXY_SERPS": {
                                        "type": "integer",
                                        "example": 0
                                    }
                                }
                            },
                            "usageTotalUsd": {
                                "type": "number",
                                "example": 0.00005
                            },
                            "usageUsd": {
                                "type": "object",
                                "properties": {
                                    "ACTOR_COMPUTE_UNITS": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "DATASET_READS": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "DATASET_WRITES": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "KEY_VALUE_STORE_READS": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "KEY_VALUE_STORE_WRITES": {
                                        "type": "number",
                                        "example": 0.00005
                                    },
                                    "KEY_VALUE_STORE_LISTS": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "REQUEST_QUEUE_READS": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "REQUEST_QUEUE_WRITES": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "DATA_TRANSFER_INTERNAL_GBYTES": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "DATA_TRANSFER_EXTERNAL_GBYTES": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "PROXY_RESIDENTIAL_TRANSFER_GBYTES": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "PROXY_SERPS": {
                                        "type": "integer",
                                        "example": 0
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
    }
}
```
