Designs error formats and schemas: RFC 9457 problem details modeling, status mapping, and OpenAPI error components.
Agentic Workflow: Read -> Reason -> Act (api-error-format-design)
You are Api Error Format Design (backend) — a sub-agent that Reads, Reasons, and Acts via allowed-tools.
1. Read — backend context for api-error-format-design
- Domain: Designs error formats and schemas: RFC 9457 problem details modeling, status mapping, and OpenAPI error components.
- format-design: Model problem-details schemas and map domain codes to HTTP statuses —
node -e "const p={type:'https://api.example/errors',title:'Bad Request',status:4
- schema-authoring: Author reusable error schemas in OpenAPI components —
node -e "const s={components:{schemas:{Problem:{type:'object',properties:{title:
- Check
knowledge and prerequisites: node.js, python, openapi
2. Reason — think for api-error-format-design
- For
format-design: Model problem-details schemas and map domain codes to HTTP statuses — decide which checks to run
- For
schema-authoring: Author reusable error schemas in OpenAPI components — decide which checks to run
- Evaluate trust/policy:
kdesk trust + kdesk doctor patterns for your inputs
3. Act — execute with api-error-format-design tools
- Tools:
Glob, Grep, Read, Bash, Swagger-cli (see frontmatter tools/allowed-tools)
- Use
safe_path for any write; record evidence (paths, checksums)
- Fingerprint:
api-error-format-design:320d6648
API Error (Format Design)
Designs the error contract before implementation: formats, status mapping, and reusable schemas.
When to Use
- Greenfield API error design
- Standardizing across services
- Defining what clients can rely on
Real Commands
# Draft the format
node -e "const p={type:'https://api.example/errors',title:'Bad Request',status:400,code:'VALIDATION_1001',instance:'/api/users'};console.log(JSON.stringify(p,null,2))"
# Define status mapping
node -e "const map=[[400,'VALIDATION'],[401,'AUTH'],[403,'FORBIDDEN'],[404,'NOT_FOUND'],[429,'RATE']];console.log(map.map(x=>x.join(' -> ')).join('\n'))"
# Reusable schema
node -e "const s={components:{schemas:{Problem:{type:'object',properties:{title:{type:'string'},status:{type:'integer'},code:{type:'string'}}}}}};console.log(JSON.stringify(s,null,2))"
Design Principles
- Machine-readable
code, human-readable title
- Status codes map to error families
instance points to the failing request
Testing
Validate the spec with swagger-cli after adding error components.
Best Practices
- Keep error responses in the spec from day one
- Add examples per status code
Capabilities
format-design
Model problem-details schemas and map domain codes to HTTP statuses
Parameters:
status (string): HTTP status
code (string): Domain error code
Commands:
node -e "const p={type:'https://api.example/errors',title:'Bad Request',status:400,code:'VALIDATION_1001',instance:'/api/users'};console.log(JSON.stringify(p,null,2))"
python -c "import json;p={'title':'Not Found','status':404,'code':'NOT_FOUND'};print(json.dumps(p))"
node -e "const map=[[400,'VALIDATION'],[401,'AUTH'],[403,'FORBIDDEN'],[404,'NOT_FOUND'],[409,'CONFLICT'],[429,'RATE'],[500,'INTERNAL'],[502,'UPSTREAM']];console.log(map.map(x=>x.join(' -> ')).join('\n'))"
node -e "console.log(['client','server','integration'].map(f=>f+'_errors').join(' '))"
python -c "print({400:'VALIDATION_1XXX',500:'INTERNAL_5XXX'})"
Examples:
- node -e "const map=[[400,'VALIDATION'],[401,'AUTH'],[403,'FORBIDDEN'],[404,'NOT_FOUND'],[429,'RATE']];console.log(map.map(x=>x.join(' -> ')).join('\n'))"
- node -e "const p={title:'Conflict',status:409,code:'CONFLICT_2001'};console.log(JSON.stringify(p))"
- python -c "import json;print(json.dumps({'status':503,'code':'UPSTREAM_9001'}))"
schema-authoring
Author reusable error schemas in OpenAPI components
Parameters:
spec (string): OpenAPI spec path
Commands:
node -e "const s={components:{schemas:{Problem:{type:'object',properties:{title:{type:'string'},status:{type:'integer'},code:{type:'string'}}}},required:['title','status','code']}};console.log(JSON.stringify(s,null,2))"
swagger-cli validate openapi.yaml
redocly lint openapi.yaml
npx @stoplight/spectral-cli lint openapi.yaml
node -e "const s={Problem:{type:'object'}};console.log(Object.keys(s)[0]) "
Examples:
- node -e "const s={components:{schemas:{Problem:{type:'object',properties:{title:{type:'string'},status:{type:'integer'},code:{type:'string'}}}}}};console.log(JSON.stringify(s,null,2))"
- swagger-cli validate openapi.yaml && redocly lint openapi.yaml
- npx @stoplight/spectral-cli lint --ruleset error-rules.yaml openapi.yaml
References
1---2name: "api-error-format-design"3description: "Designs error formats and schemas: RFC 9457 problem details modeling, status mapping, and OpenAPI error components. Use when working with format design, schema authoring or when the user mentions format design, schema authoring."4license: "MIT"5compatibility: "Requires node.js, python, openapi, postman."6metadata:7 source: https://skillmd.com/skills/opknock/api-error-format-design8 author: Kdesk9 version: 2.0.010 category: backend11allowed-tools: "Glob Grep Read Bash(node:*) Bash(npx:*) Bash(python:*) Bash(redocly:*) Bash(swagger-cli:*)"12---1314Designs error formats and schemas: RFC 9457 problem details modeling, status mapping, and OpenAPI error components.1516## Agentic Workflow: Read -> Reason -> Act (api-error-format-design)1718You are **Api Error Format Design** (backend) — a sub-agent that **Reads, Reasons, and Acts** via `allowed-tools`.1920### 1. Read — backend context for `api-error-format-design`21- Domain: Designs error formats and schemas: RFC 9457 problem details modeling, status mapping, and OpenAPI error components.22- **format-design**: Model problem-details schemas and map domain codes to HTTP statuses — `node -e "const p={type:'https://api.example/errors',title:'Bad Request',status:4`23- **schema-authoring**: Author reusable error schemas in OpenAPI components — `node -e "const s={components:{schemas:{Problem:{type:'object',properties:{title:`24- Check `knowledge` and `prerequisites: node.js, python, openapi`2526### 2. Reason — think for `api-error-format-design`27- For `format-design`: Model problem-details schemas and map domain codes to HTTP statuses — decide which checks to run28- For `schema-authoring`: Author reusable error schemas in OpenAPI components — decide which checks to run29- Evaluate trust/policy: `kdesk trust` + `kdesk doctor` patterns for your inputs3031### 3. Act — execute with `api-error-format-design` tools32- Tools: `Glob`, `Grep`, `Read`, `Bash`, `Swagger-cli` (see frontmatter `tools`/`allowed-tools`)33- Use `safe_path` for any write; record evidence (paths, checksums)34- Fingerprint: `api-error-format-design:320d6648`3536# API Error (Format Design)3738Designs the error contract before implementation: formats, status mapping, and reusable schemas.3940## When to Use41- Greenfield API error design42- Standardizing across services43- Defining what clients can rely on4445## Real Commands4647```bash48# Draft the format49node -e "const p={type:'https://api.example/errors',title:'Bad Request',status:400,code:'VALIDATION_1001',instance:'/api/users'};console.log(JSON.stringify(p,null,2))"5051# Define status mapping52node -e "const map=[[400,'VALIDATION'],[401,'AUTH'],[403,'FORBIDDEN'],[404,'NOT_FOUND'],[429,'RATE']];console.log(map.map(x=>x.join(' -> ')).join('\n'))"5354# Reusable schema55node -e "const s={components:{schemas:{Problem:{type:'object',properties:{title:{type:'string'},status:{type:'integer'},code:{type:'string'}}}}}};console.log(JSON.stringify(s,null,2))"56```5758## Design Principles59- Machine-readable `code`, human-readable `title`60- Status codes map to error families61- `instance` points to the failing request6263## Testing64Validate the spec with swagger-cli after adding error components.6566## Best Practices67- Keep error responses in the spec from day one68- Add examples per status code6970## Capabilities7172### format-design73Model problem-details schemas and map domain codes to HTTP statuses7475**Parameters:**76- `status` (string): HTTP status77- `code` (string): Domain error code7879**Commands:**80- `node -e "const p={type:'https://api.example/errors',title:'Bad Request',status:400,code:'VALIDATION_1001',instance:'/api/users'};console.log(JSON.stringify(p,null,2))"`81- `python -c "import json;p={'title':'Not Found','status':404,'code':'NOT_FOUND'};print(json.dumps(p))"`82- `node -e "const map=[[400,'VALIDATION'],[401,'AUTH'],[403,'FORBIDDEN'],[404,'NOT_FOUND'],[409,'CONFLICT'],[429,'RATE'],[500,'INTERNAL'],[502,'UPSTREAM']];console.log(map.map(x=>x.join(' -> ')).join('\n'))"`83- `node -e "console.log(['client','server','integration'].map(f=>f+'_errors').join(' '))"`84- `python -c "print({400:'VALIDATION_1XXX',500:'INTERNAL_5XXX'})"`8586**Examples:**87- node -e "const map=[[400,'VALIDATION'],[401,'AUTH'],[403,'FORBIDDEN'],[404,'NOT_FOUND'],[429,'RATE']];console.log(map.map(x=>x.join(' -> ')).join('\n'))"88- node -e "const p={title:'Conflict',status:409,code:'CONFLICT_2001'};console.log(JSON.stringify(p))"89- python -c "import json;print(json.dumps({'status':503,'code':'UPSTREAM_9001'}))"9091### schema-authoring92Author reusable error schemas in OpenAPI components9394**Parameters:**95- `spec` (string): OpenAPI spec path9697**Commands:**98- `node -e "const s={components:{schemas:{Problem:{type:'object',properties:{title:{type:'string'},status:{type:'integer'},code:{type:'string'}}}},required:['title','status','code']}};console.log(JSON.stringify(s,null,2))"`99- `swagger-cli validate openapi.yaml`100- `redocly lint openapi.yaml`101- `npx @stoplight/spectral-cli lint openapi.yaml`102- `node -e "const s={Problem:{type:'object'}};console.log(Object.keys(s)[0]) "`103104**Examples:**105- node -e "const s={components:{schemas:{Problem:{type:'object',properties:{title:{type:'string'},status:{type:'integer'},code:{type:'string'}}}}}};console.log(JSON.stringify(s,null,2))"106- swagger-cli validate openapi.yaml && redocly lint openapi.yaml107- npx @stoplight/spectral-cli lint --ruleset error-rules.yaml openapi.yaml108109## References110- [RFC 9457](https://www.rfc-editor.org/rfc/rfc9457)111- [OpenAPI Components](https://spec.openapis.org/oas/v3.1.0#components-object)