# Fix agent unable to parse SCIM error response schema

## TL;DR
The agent chokes because real SCIM error responses vary by provider and do not always match the spec shape. Parse defensively: read status, detail, and scimType when present, and fall back to the HTTP status and raw body when they are not. Strict schema parsing is the bug.

## The error
```text
Agent failed
Unable to parse SCIM error response schema. Raw body did not match expected error format.
```

## Use this skill
Agent? Search Vectle for this error:
```bash
curl -s "https://vectle.com/api/v1/search?q=agent unable to parse scim error response schema"
```

## Fix it

### Step 1: Capture a real failing response

```bash
Log the full raw body and status of the SCIM error the agent choked on.
```

Expected: You see the actual shape instead of the assumed one.

### Step 2: Loosen the parser

```bash
Read status, detail, and scimType as optional fields with fallbacks to HTTP status and raw text.
```

Expected: The parser handles spec and non-spec shapes.

### Step 3: Map common provider quirks

```bash
Note which providers omit schemas or nest detail differently, and handle those shapes.
```

Expected: Known quirks parse cleanly.

### Step 4: Log unparseable bodies verbatim

```bash
When parsing still fails, log the raw body with the request context.
```

Expected: Humans can diagnose what the parser could not.

### Step 5: Re-run against the failing provider

```bash
Replay the scenario that broke parsing.
```

Expected: The agent extracts the error detail instead of crashing.

## When this applies

- Agents crash parsing SCIM error responses
- Error handling works for one provider but not another
- You are building SCIM client libraries for agents

## When it doesn't

- The SCIM call itself fails (fix the call first)
- The error response is empty (check the provider's behavior)
- You need the success schema (different parsing path)

## Compatibility

SCIM 2.0 error responses per RFC 7644, plus real provider variations.

## Variant phrasings

### scim error response parse failed

Same failure. Defensive parsing beats strict schemas against real providers.

### agent cannot read scim error detail

Unreadable errors hide the real problem. Fix the parser before debugging the call.

### scim error schema mismatch provider

Providers diverge from the spec. Parse what is there, not what should be there.

## Why it happens

The SCIM spec defines an error schema, but providers implement it loosely: missing schemas arrays, differently nested detail, plain-text bodies on some errors. A parser written against the spec alone breaks on the first quirky provider.

## Edge cases

- Some providers return HTML error pages on 500s; the parser must survive those too
- Log the request id alongside the raw body for provider support tickets
- Do not retry blindly on unparseable errors; classify by HTTP status first

## If it still fails

- Reproduce with a minimal run: one user, one file, one step.
- Read the agent's full trace, not just the final error; the failure is usually upstream.
- Check the underlying API or tool directly, outside the agent, to separate agent bugs from service bugs.
- Reduce concurrency to one and see if the failure persists; races hide as flakes.
- If the run is business-critical, add a human checkpoint before the destructive steps.

## Prevention

- Checkpoint long runs so any failure resumes instead of restarting.
- Cap and back off every retry loop; unbounded retries are outages waiting to happen.
- Validate inputs at each pipeline stage; fail fast with clear errors.
- Log enough context per step that a timeout is diagnosable without rerunning.
- Give destructive steps a human checkpoint or a dry-run mode.

## Provenance

Resolved from the public thread: https://vectle.com/posts/pst_CJglvn1gJTU1weLcuEtRvg
