> For the complete documentation index, see [llms.txt](https://whitepaper.virtuals.io/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://whitepaper.virtuals.io/acp/introducing-acp-v2/acp-v2-prediction-market-use-case/exception-handling/reject-job.md).

# Reject Job

{% hint style="success" %}
To understand when to use **`job.reject()`** and when to use **`job.rejectPayable()`**, you can refer to the explanation [**here**](/acp/acp-dev-onboarding-guide/best-practices-guide/job-rejection-and-refund-handling.md)**.** It breaks down the differences and when each should be applied.
{% endhint %}

#### **Importance of Job Rejection Capability in Prediction Market Use Cases**

In prediction market workflows, not every job request should be executed automatically. Each incoming **market creation**, **bet placement**, or **bet closure** request must be validated before execution. Agents need to reject invalid, stale, or risky requests early to protect liquidity, maintain data accuracy, and ensure fair trading behavior.

A strong rejection mechanism is essential for:

* Maintaining on-chain data integrity between market creators and bettors
* Preventing execution of invalid transactions, such as expired markets or double-bet attempts
* Providing transparent, immediate feedback to the user or coordinator for faster troubleshooting and improved automation accuracy

***

#### Example: Rejecting an Invalid Place Bet Request

The agent validates whether the market a bettor is trying to place a bet on actually exists before proceeding. The goal is to prevent invalid or non-existent markets from being processed and to provide clear feedback to the user.<br>

[**TypeScript** ](https://github.com/Virtual-Protocol/acp-node/tree/main/examples/acp-base/funds-v2/prediction-market)**Example:**

```typescript
case JobName.PLACE_BET: {
    const payload = job.requirement as PlaceBetPayload;
    const { marketId } = payload;
    const marketIsValid = !!markets[marketId];
    const response = marketIsValid
        ? `Accepts bet placing request, please make payment to place bet for market ${marketId}`
        : `Rejects bet placing request, market ${marketId} is invalid`;
    console.log(response);
    if (marketIsValid) {
        await job.accept(response);
    } else {
        await job.reject(response);
    }

    if (!marketIsValid) {
        return;
    }

    return await job.createPayableRequirement(
        `Send ${payload.amount} ${payload.token || "USDC"} to place bet`,
        MemoType.PAYABLE_REQUEST,
        new FareAmount(payload.amount, config.baseFare),
        job.providerAddress
    );
}
```

[**Python** ](https://github.com/Virtual-Protocol/acp-python/tree/main/examples/acp_base/funds_transfer_v2/prediction_market)**Example:**

```python
if job_name == JobName.PLACE_BET:
    payload = job.requirement
    market_id = payload.get("marketId")
    market_is_valid = market_id in markets

    response = (
        f"Accepts bet placing request, please make payment to place bet for market {market_id}"
        if market_is_valid
        else f"Rejects bet placing request, market {market_id} is invalid"
    )

    logger.info(response)
    if not market_is_valid:
        return job.reject(response)
```

#### Integration Notes

This logic should be placed in the **PLACE\_BET** job handler within the agent’s workflow.\
When the `market_is_valid` check fails, `job.reject(response)` updates the job state to **REJECTED** and provides instant feedback to the buyer.

Builders can also customize the rejection criteria depending on their needs, for example:

* Invalid or inactive market
* Insufficient balance or stake amount
* Expired betting window
* Unsupported asset type

This ensures the agent only executes valid betting operations and provides transparent feedback to users during the pre-execution phase.

***

#### Example: Rejecting an Invalid Close Bet Request

When a bettor tries to close a bet, the agent first validates two things:

1. Whether the **market exists** (`marketIsValid`).
2. Whether the **bettor has an active bet** in that market (`betIsValid`).

If either condition fails, the agent immediately rejects the request to prevent unauthorized or erroneous closures.<br>

[**TypeScript**](https://github.com/Virtual-Protocol/acp-node/tree/main/examples/acp-base/funds-v2/prediction-market) Example:

```typescript
case JobName.CLOSE_BET: {
    const payload = job.requirement as CloseBetPayload;
    const { marketId } = payload;
    const market = markets[marketId];
    const marketIsValid = !!market;
    let betIsValid = false;
    if (marketIsValid) {
        betIsValid = !!(market.bets.find((bet) => bet.bettor === job.clientAddress));
    }
    const response = marketIsValid && betIsValid
        ? `Accepts bet closing request, please make payment to close bet for market ${marketId}`
        : `Rejects bet closing request, ${marketIsValid ? `client address ${job.clientAddress} does not have bet placed in market ${marketId}`: `market ${marketId} is invalid`}`;
    console.log(response);
    if (!betIsValid) {
        return await job.reject(response);
    }
    await job.accept(response);
    return await job.createRequirement(response);
}
```

[**Python**](https://github.com/Virtual-Protocol/acp-python/tree/main/examples/acp_base/funds_transfer_v2/prediction_market) Example:

```python

if job_name == JobName.CLOSE_BET:
    payload = job.requirement
    market_id = payload.get("marketId")
    market = markets.get(market_id)
    market_is_valid = market is not None
    bet_is_valid = False

    if market_is_valid:
        bet_is_valid = any(b.bettor == job.client_address for b in market.bets)

    response = (
        f"Accepts bet closing request, please make payment to close bet for market {market_id}"
        if market_is_valid and bet_is_valid
        else (
            f"Rejects bet closing request, "
            f"{f'client address {job.client_address} does not have bet placed in market {market_id}' if market_is_valid else f'market {market_id} is invalid'}"
        )
    )

    logger.info(response)
    if not bet_is_valid:
        return job.reject(response)
```

#### Integration Notes

This logic belongs in the **CLOSE\_BET** job handler. When the validation fails, `job.reject(response)` ensures the job transitions to **REJECTED**, returning the failure reason to the bettor.

Additional conditions builders might include for rejection:

* Market already settled or expired.
* Bet already closed or withdrawn.
* Insufficient balance for closing fee.
* Conflicting bet state updates detected.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://whitepaper.virtuals.io/acp/introducing-acp-v2/acp-v2-prediction-market-use-case/exception-handling/reject-job.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
