Skip to main content

URL JSON Provider

Load attack goals from remote JSON endpoints directly into memory.

When to Use

Use the URL JSON provider when you:

  • Want to consume a dataset published as a JSON URL
  • Need a lightweight source without local files or HuggingFace setup
  • Evaluate dynamic/public benchmark feeds

Configuration Options

OptionTypeRequiredDefaultDescription
providerstringYesMust be "url_json"
urlstringYesHTTPS URL returning JSON
goal_fieldstringNo"instruction"Primary field containing the goal text
fallback_fieldslistNo["prompt", "input", "text"]Alternative fields if goal_field is missing
extra_fieldslistNo[]Additional fields to keep with each goal
limitintNoMaximum number of goals
shuffleboolNofalseRandomize goal selection
seedintNoRandom seed for reproducibility

Basic Usage

attack_config = {
"attack_type": "baseline",
"dataset": {
"provider": "url_json",
"url": "https://yunhao-feng.github.io/AgentHazard/data/dataset.json",
"goal_field": "query",
"fallback_fields": ["prompt", "input", "text"],
"limit": 100,
"shuffle": True,
"seed": 42,
},
}

results = agent.hack(attack_config=attack_config)

Wrapped JSON Support

The provider accepts both:

  • Top-level JSON arrays
  • JSON objects containing list keys like data, samples, records, or items

Example payloads:

[
{"query": "Goal A"},
{"query": "Goal B"}
]
{
"records": [
{"query": "Goal A"},
{"query": "Goal B"}
]
}

Structured Output With Metadata

When you need metadata alongside the goal text, use extra_fields and provider-level access:

from hackagent.datasets import get_provider

provider = get_provider(
"url_json",
{
"url": "https://yunhao-feng.github.io/AgentHazard/data/dataset.json",
"goal_field": "query",
"extra_fields": ["category", "decomposed_query", "jailbreak_method"],
},
)

rows = provider.load_goals(limit=5, return_dicts=True)
extras = provider.get_extra_data()

print(rows[0])
print(extras[0])

Notes

  • The dataset is downloaded once and cached in memory per provider instance.
  • Use trusted URLs and pin sources when reproducibility is critical.
  • For static/private data, the File Provider can be preferable.