Problem Details Rfc9457のロゴ

Problem Details Rfc9457

コミュニティ
fatonh
problem-details-rfc9457

Use when generating error responses, exception listeners, or custom exceptions in a Symfony API. Defines RFC 9457 (problem+json) error format, mapping domain exceptions to HTTP status codes, and a single kernel exception listener. Use when the task mentions error handling, exception listener, error response, or problem details.

概要

公開者fatonh
リポジトリsymfony-skills
スキル名problem-details-rfc9457
スター
36
フォーク
3
同梱ファイル
指示のみ
ライセンスMIT
リンク
  • Markdown形式の指示

    モデルが必要に応じて読み込むSKILL.mdファイルです。関連するリクエストがあったときだけトークンを消費します。

  • どのLLMでも利用可能

    AIスキルはプロバイダー固有のコードではなく、通常のMarkdownなので、GPT、Claude、Gemini、Grok、ローカルモデルで利用できます。

  • 指示だけで完結

    モデルに必要なものはすべて指示に含まれているため、別途同期するファイルはありません。

  • オープンソース

    fatonhがGitHubで公開しています。インストールする前にソースを確認してください。

インストール

AIスキル「Problem Details Rfc9457」をTypingMindにインストールすれば、どのLLMでも利用できます。SKILL.mdを読み取れる別のAIエージェントに追加することもできます。

1

TypingMindにインストール

TypingMindはGitHubフォルダから直接スキルをインストールします。SKILL.mdを読み取り、リソースファイルをまとめてローカルに保存します。

  1. アプリを開き、「プラグイン」→「スキル」に移動します。
  2. 「GitHubからインストール」を選択します。
  3. 以下のスキルフォルダのURLを貼り付けて確定します。
    https://github.com/fatonh/symfony-skills/tree/main/skills/problem-details-rfc9457
  4. スキルを利用したいチャットごとに、そのスキルを有効にしてください。
「プラグイン」→「スキル」→「スキルを追加」→「GitHubのURLから」を選択し、フォルダのURLを貼り付けて「続行」を押します。
2

別のAIエージェントにインストール

Agent Skills形式を読み取れるAIエージェントなら、このスキルを利用できます。フォルダをそのAIエージェントのスキルディレクトリにコピーしてください。

Claude Code — .claude/skills
git clone --depth 1 https://github.com/fatonh/symfony-skills.git /tmp/symfony-skills
mkdir -p .claude/skills
cp -r /tmp/symfony-skills/skills/problem-details-rfc9457 .claude/skills/problem-details-rfc9457
コピー後、新しいスキルを読み込むためにClaude Codeを再起動してください。

TypingMindで使用

TypingMindのチャットでProblem Details Rfc9457を有効にするだけで、あとはモデルが対応します。名前と説明がシステムプロンプトに含まれ、関連するリクエストがあると、モデルが指示の全文を自動で読み込みます。手動で呼び出す必要はなく、実際に使用されるまでトークンを消費しません。

関連するリクエストがあるとすぐに、モデルが自動的にProblem Details Rfc9457を読み込みます。

どのAIモデルでも利用可能

AIスキルはプロバイダー固有のコードではなく、通常のMarkdownで書かれた指示です。そのため、Problem Details Rfc9457は作成時に想定されたモデルに縛られません。TypingMindに一度インストールすれば、ご自身のAPIキーを使って、GPT-5、Claude、Gemini、Grok、DeepSeek、Mistral、Llama、またはご自身で実行するローカルモデルで利用できます。

  • 必要なときだけ読み込み

    システムプロンプトには名前と説明だけが含まれます。関連するリクエストが初めてあったときに指示を取得するため、スキルを使わない間は指示の読み込みにトークンを消費しません。

  • チャットの途中でモデルを切り替え

    スキルはコードではなく指示なので、モデルを切り替えてもそのまま使えます。次のモデルも同じSKILL.mdを読み込みます。

スキルの指示

モデルが読み込むSKILL.mdの内容です。スキルはモデルが従う指示なので、インストールする前に確認してください。

RFC 9457 Problem Details (Symfony)

The format

Every error response is application/problem+json per RFC 9457:

json
{
  "type": "https://api.example.com/problems/order-not-found",
  "title": "Order not found",
  "status": 404,
  "detail": "No order exists with id 018f...",
  "instance": "/api/orders/018f...",
  "errors": [
    { "field": "items", "message": "This collection should contain 1 element or more." }
  ]
}
  • type — a stable URI identifying the problem class (dereferenceable docs ideally).
  • title — short, human-readable, same for every occurrence of this type.
  • status — the HTTP status code, duplicated in the body.
  • detail — specific to this occurrence.
  • instance — the request URI that produced it.
  • Extension members (errors, traceId, …) are allowed and encouraged.

Domain exceptions carry their own HTTP semantics

Define a base exception that knows its status and problem type. Throw it from services/domain; never build error JSON in a controller.

php
abstract class DomainException extends \RuntimeException
{
    abstract public function statusCode(): int;

    abstract public function problemType(): string;

    public function title(): string
    {
        return (new \ReflectionClass($this))->getShortName();
    }
}

final class OrderNotFoundException extends DomainException
{
    public function __construct(Uuid $id)
    {
        parent::__construct("No order exists with id {$id->toRfc4122()}");
    }

    public function statusCode(): int { return Response::HTTP_NOT_FOUND; }

    public function problemType(): string { return 'https://api.example.com/problems/order-not-found'; }

    public function title(): string { return 'Order not found'; }
}

One exception listener, not try/catch everywhere

php
#[AsEventListener(event: KernelEvents::EXCEPTION, priority: 0)]
final class ProblemDetailsExceptionListener
{
    public function __construct(
        private readonly LoggerInterface $logger,
        #[Autowire('%kernel.debug%')] private readonly bool $debug,
    ) {}

    public function __invoke(ExceptionEvent $event): void
    {
        $e = $event->getThrowable();
        $request = $event->getRequest();

        $problem = match (true) {
            $e instanceof DomainException             => $this->fromDomain($e, $request),
            $e instanceof ValidationFailedException   => $this->fromValidation($e, $request),
            $e instanceof HttpExceptionInterface      => $this->fromHttp($e, $request),
            default                                   => $this->fromUnexpected($e, $request),
        };

        if ($problem['status'] >= 500) {
            $this->logger->error($e->getMessage(), ['exception' => $e]);
        }

        $event->setResponse(new JsonResponse(
            $problem,
            $problem['status'],
            ['Content-Type' => 'application/problem+json'],
        ));
    }

    private function fromDomain(DomainException $e, Request $request): array
    {
        return [
            'type'     => $e->problemType(),
            'title'    => $e->title(),
            'status'   => $e->statusCode(),
            'detail'   => $e->getMessage(),
            'instance' => $request->getPathInfo(),
        ];
    }

    private function fromValidation(ValidationFailedException $e, Request $request): array
    {
        $errors = [];
        foreach ($e->getViolations() as $v) {
            $errors[] = ['field' => $v->getPropertyPath(), 'message' => $v->getMessage()];
        }

        return [
            'type'     => 'https://api.example.com/problems/validation-error',
            'title'    => 'Validation failed',
            'status'   => Response::HTTP_UNPROCESSABLE_ENTITY,
            'detail'   => 'The request payload did not pass validation.',
            'instance' => $request->getPathInfo(),
            'errors'   => $errors,
        ];
    }

    private function fromHttp(HttpExceptionInterface $e, Request $request): array
    {
        return [
            'type'     => 'about:blank',
            'title'    => Response::$statusTexts[$e->getStatusCode()] ?? 'Error',
            'status'   => $e->getStatusCode(),
            'detail'   => $e->getMessage(),
            'instance' => $request->getPathInfo(),
        ];
    }

    private function fromUnexpected(\Throwable $e, Request $request): array
    {
        return [
            'type'     => 'about:blank',
            'title'    => 'Internal Server Error',
            'status'   => Response::HTTP_INTERNAL_SERVER_ERROR,
            // Never leak internals in prod.
            'detail'   => $this->debug ? $e->getMessage() : 'An unexpected error occurred.',
            'instance' => $request->getPathInfo(),
        ];
    }
}

Don't leak internals

  • In prod, the detail for 5xx must be generic — never the exception message or stack trace.
  • Log the full exception server-side with a traceId; return that id so support can correlate.
  • Never echo SQL, file paths, or class names to the client.

API Platform note

API Platform 4 already emits problem+json. You only need this listener for non-API-Platform controllers, or to customize the problem type/extensions. Map domain exceptions to status codes via config/packages/api_platform.yaml exception_to_status.

Gotchas

  • Agent builds ['error' => '...'] ad-hoc JSON — use the RFC 9457 shape with type/title/status/detail/instance.
  • Agent sets Content-Type: application/json for errors — use application/problem+json.
  • Agent try/catches in each controller — centralize in one KernelEvents::EXCEPTION listener.
  • Agent leaks $e->getMessage() / stack traces on 5xx in prod — gate behind kernel.debug.
  • Agent uses HTTP 400 for validation errors — Symfony convention is 422 Unprocessable Entity.
  • Agent forgets to log 5xx — log server-side; only the safe summary goes to the client.
  • Agent reinvents an exception hierarchy per feature — extend the shared DomainException base.

よくある質問

AIスキル「Problem Details Rfc9457」では何ができますか?

Use when generating error responses, exception listeners, or custom exceptions in a Symfony API. Defines RFC 9457 (problem+json) error format, mapping domain exceptions to HTTP status codes, and a single kernel exception listener. Use when the task mentions error handling, exception listener, error response, or problem details.

TypingMindでProblem Details Rfc9457を使うメリットは何ですか?

一度インストールすれば、どのモデルでも使えるからです。Problem Details Rfc9457はプロバイダー固有のコードではなく、通常のMarkdownで記述されているため、同じスキルをGPT-5、Claude、Gemini、Grok、ローカルモデルで利用できます。チャットの途中でモデルを切り替えても、そのまま使い続けられます。TypingMindは自分のAPIキーで動作するため、シート単位のサブスクリプションではなく、プロバイダーに直接料金を支払います。スキルとチャットは自分のストレージに保持されます。

TypingMindにProblem Details Rfc9457をインストールするにはどうすればよいですか?

TypingMindで「プラグイン」→「スキル」→「GitHubからインストール」を開き、https://github.com/fatonh/symfony-skills/tree/main/skills/problem-details-rfc9457を貼り付けてください。TypingMindがSKILL.mdを読み込み、チャットごとに有効にできるスキルとしてインストールします。

Problem Details Rfc9457を使えるAIモデルはどれですか?

TypingMindに接続したどのモデルでも利用できます。AIスキルはプロバイダー固有のコードではなく、通常のMarkdownで書かれた指示です。そのため、GPT、Claude、Gemini、Grok、ローカルモデルのいずれも、リクエストの内容がこのスキルの用途に合ったときに、このスキルを読み込めます。

Problem Details Rfc9457で使えるAIモデルの数に制限はありますか?

数に制限はありません。スキルに対応したモデルであれば、GPT、Claude、Gemini、Grok、DeepSeek、Mistral、Llamaなど、どのモデルでもProblem Details Rfc9457を利用できます。すべてTypingMind上で、自分のAPIキーを使って利用できます。

AIスキル「Problem Details Rfc9457」は無料ですか?

はい。fatonhがMITライセンスのもとでGitHubに公開しています。ご利用のAIプロバイダーに支払うのは、使用したトークンの料金だけです。

AIスキルとは何ですか?

AIスキルは、特定のタスクの実行方法をAIモデルに教える、再利用可能な指示のセットです。オープンなAgent Skills形式に従い、名前と説明を含むSKILL.mdファイルに加え、モデルが必要とするスクリプト、テンプレート、参照ファイルで構成されます。モデルはリクエストがスキルに合致したときだけ指示を読み込むため、インストール済みのスキルも、使うまでは費用がかかりません。

AIスキルは、プラグインやMCPサーバーとどう違いますか?

プラグインやMCPサーバーは、モデルが呼び出せる新しいツールを提供します。ツールとは、どこかで実行され、結果を返すコードです。一方、AIスキルは、タスクへの取り組み方、従うべき手順、望ましい出力の例といった知識や進め方をモデルに伝えます。スキルは通常のMarkdownで記述されているため、サーバー、APIキー、実行環境は不要で、どのモデルでも利用できます。

すべて見る

今すぐ自分専用のAIワークスペースを作成

ニュースレターに登録すると、新機能や今後のプレゼント企画のお知らせが届きます👇