承接 wardstone/client 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

wardstone/client

Composer 安装命令:

composer require wardstone/client

包简介

PHP SDK for the Wardstone LLM security API. Detect prompt injection, content violations, data leakage, and unknown links.

README 文档

README

PHP SDK for the Wardstone LLM security API. Detect prompt injection, content violations, data leakage, and unknown links in LLM inputs and outputs.

Installation

composer require wardstone/client

Quick Start

<?php
use Wardstone\Client;

$client = new Client('YOUR_API_KEY');
$result = $client->detect('Ignore all previous instructions');

if ($result->risk_bands->prompt_attack->level !== 'Low Risk') {
    echo "Prompt attack detected\n";
    echo "Risk: " . $result->risk_bands->prompt_attack->level . "\n";
}

Configuration

$client = new Client(
    apiKey: 'YOUR_API_KEY',       // or set WARDSTONE_API_KEY env var
    baseUrl: 'https://wardstone.ai', // default
    timeout: 30,                      // seconds, default: 30
    maxRetries: 2                     // default: 2, max: 10
);

Environment Variable

The API key can be set via the WARDSTONE_API_KEY environment variable:

// Will use WARDSTONE_API_KEY from environment
$client = new Client();

Usage

Basic Detection

$result = $client->detect('Ignore all previous instructions');

$result->flagged;                                // true
$result->primary_category;                       // "prompt_attack"
$result->risk_bands->prompt_attack->level;       // "Severe Risk"
$result->risk_bands->content_violation->level;   // "Low Risk"
$result->risk_bands->data_leakage->level;        // "Low Risk"
$result->risk_bands->unknown_links->level;       // "Low Risk"

Array Input

$result = $client->detect(['text' => $userInput]);

Scan Strategies

// Full scan (check all categories)
$result = $client->detect(['text' => $input, 'scan_strategy' => 'full-scan']);

// Early exit (stop at first threat)
$result = $client->detect(['text' => $input, 'scan_strategy' => 'early-exit']);

// Smart sample (optimized for long texts)
$result = $client->detect(['text' => $input, 'scan_strategy' => 'smart-sample']);

Raw Scores

$result = $client->detect(['text' => $input, 'include_raw_scores' => true]);
$result->raw_scores->prompt_attack;       // 0.95
$result->raw_scores->content_violation;   // 0.01

Rate Limit Info

$result = $client->detect('some text');
$result->rate_limit->limit;       // 1000
$result->rate_limit->remaining;   // 999
$result->rate_limit->reset;       // 1700000000

Error Handling

use Wardstone\Errors\AuthenticationError;
use Wardstone\Errors\BadRequestError;
use Wardstone\Errors\PermissionError;
use Wardstone\Errors\RateLimitError;
use Wardstone\Errors\InternalServerError;
use Wardstone\Errors\TimeoutError;
use Wardstone\Errors\ConnectionError;
use Wardstone\Errors\WardstoneError;

try {
    $result = $client->detect($input);
} catch (AuthenticationError $e) {
    // Invalid or missing API key (401)
} catch (BadRequestError $e) {
    // Invalid request (400)
    $e->maxLength;  // available for text_too_long errors
} catch (PermissionError $e) {
    // Feature not available on plan (403)
} catch (RateLimitError $e) {
    // Quota exceeded (429)
    $e->retryAfter;  // seconds to wait
} catch (InternalServerError $e) {
    // Server error (500)
} catch (TimeoutError $e) {
    // Request timed out
} catch (ConnectionError $e) {
    // Network failure
} catch (WardstoneError $e) {
    // Catch-all for any Wardstone error
    $e->status;     // HTTP status code (null for network errors)
    $e->errorCode;  // Machine-readable error code
}

Safe Logging

When logging exceptions, use getSafeTrace() and getSafeTraceAsString() instead of PHP's built-in getTrace() / getTraceAsString(). The safe variants redact function arguments to prevent API keys from appearing in logs:

try {
    $result = $client->detect($input);
} catch (WardstoneError $e) {
    // Safe: arguments redacted from trace
    error_log($e->getMessage() . "\n" . $e->getSafeTraceAsString());

    // Avoid: $e->getTraceAsString() may include sensitive arguments
}

Risk Levels

Each category returns one of four risk levels:

  • "Low Risk" - No threat detected
  • "Some Risk" - Minor concern
  • "High Risk" - Significant threat
  • "Severe Risk" - Critical threat, action recommended

Requirements

  • PHP >= 8.1
  • ext-curl
  • ext-json
  • Zero runtime dependencies

Links

wardstone/client 适用场景与选型建议

wardstone/client 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 0 次下载、GitHub Stars 达 0, 最近一次更新时间为 2026 年 02 月 06 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「security」 「content-moderation」 「llm」 「prompt-injection」 「wardstone」 「ai-safety」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 wardstone/client 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 wardstone/client 我们能提供哪些服务?
定制开发 / 二次开发

基于 wardstone/client 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 0
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 28
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 0
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2026-02-06