Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
81 commits
Select commit Hold shift + click to select a range
073cf62
Drafting a quick test script
riedgar-ms Nov 7, 2025
244f2cf
Corrected JSON support
riedgar-ms Nov 7, 2025
9fccc5b
Expand testing
riedgar-ms Nov 7, 2025
dd36ea2
Don't need this
riedgar-ms Nov 7, 2025
170b16b
Some small refinements
riedgar-ms Nov 7, 2025
dd56600
Draft unit test updates
riedgar-ms Nov 7, 2025
8df25b9
Merge remote-tracking branch 'origin/main' into riedgar-ms/selfask-sc…
riedgar-ms Nov 9, 2025
5405dec
Merge remote-tracking branch 'origin/main' into riedgar-ms/selfask-sc…
riedgar-ms Nov 13, 2025
fa4ca37
Proposal for schema smuggling
riedgar-ms Nov 13, 2025
7390271
Merge remote-tracking branch 'origin/main' into riedgar-ms/selfask-sc…
riedgar-ms Nov 13, 2025
320d58c
Linting issues
riedgar-ms Nov 13, 2025
842cd03
Merge remote-tracking branch 'origin/main' into riedgar-ms/selfask-sc…
riedgar-ms Nov 13, 2025
80e8cd4
Merge remote-tracking branch 'origin/main' into riedgar-ms/selfask-sc…
riedgar-ms Nov 14, 2025
2003466
Merge remote-tracking branch 'origin/main' into riedgar-ms/selfask-sc…
riedgar-ms Nov 14, 2025
45cb825
Add the JSONResponseConfig class
riedgar-ms Nov 15, 2025
ec4efaa
Better name
riedgar-ms Nov 15, 2025
1eb4395
Start on other changes
riedgar-ms Nov 15, 2025
29fdb2f
Next changes
riedgar-ms Nov 15, 2025
2c8e919
Try dealing with some linting
riedgar-ms Nov 15, 2025
9009edf
More changes....
riedgar-ms Nov 16, 2025
d899af4
Correct responses setup
riedgar-ms Nov 16, 2025
c78f819
blacken
riedgar-ms Nov 16, 2025
45f73a6
Fix a test....
riedgar-ms Nov 16, 2025
becb214
Fix reponses tests
riedgar-ms Nov 16, 2025
f37d070
Fix chat target tests
riedgar-ms Nov 16, 2025
6072ae3
blacken
riedgar-ms Nov 16, 2025
4262cd7
Merge remote-tracking branch 'origin/main' into riedgar-ms/selfask-sc…
riedgar-ms Nov 20, 2025
970c4f2
Merge remote-tracking branch 'origin/main' into riedgar-ms/selfask-sc…
riedgar-ms Nov 21, 2025
55502ff
Merge remote-tracking branch 'origin/main' into riedgar-ms/selfask-sc…
riedgar-ms Nov 21, 2025
388f138
Resync with origin/main
riedgar-ms Dec 2, 2025
b6182e9
Merge from main
riedgar-ms Dec 3, 2025
630842a
Merge remote-tracking branch 'origin/main' into riedgar-ms/selfask-sc…
Dec 8, 2025
4da3b9d
Merge remote-tracking branch 'origin/main' into riedgar-ms/selfask-sc…
riedgar-ms Dec 8, 2025
fd03bba
Merge remote-tracking branch 'origin/main' into riedgar-ms/selfask-sc…
riedgar-ms Dec 10, 2025
21fe8a0
Merge remote-tracking branch 'origin/main' into riedgar-ms/selfask-sc…
riedgar-ms Dec 11, 2025
48c61cc
Switching auth
riedgar-ms Dec 11, 2025
cf71d2d
Merge remote-tracking branch 'origin/main' into riedgar-ms/selfask-sc…
riedgar-ms Dec 12, 2025
d231d79
Merge remote-tracking branch 'origin/main' into riedgar-ms/selfask-sc…
riedgar-ms Dec 13, 2025
c8b4d0d
Working on next bit
riedgar-ms Dec 13, 2025
03c59a6
Get one test working again...
riedgar-ms Dec 13, 2025
5275b14
Should be the final test working (plus linting)
riedgar-ms Dec 13, 2025
9dfdcf6
Think this is the other place?
riedgar-ms Dec 13, 2025
5cef55d
Missing import?
riedgar-ms Dec 13, 2025
bea538c
And another
riedgar-ms Dec 13, 2025
e5bbea0
Sort imports
riedgar-ms Dec 13, 2025
f325976
A bad merge
riedgar-ms Dec 13, 2025
271ea14
More missed merges
riedgar-ms Dec 13, 2025
e90e409
ruff fix
riedgar-ms Dec 13, 2025
b1a7fdb
Merge remote-tracking branch 'origin/main' into riedgar-ms/selfask-sc…
riedgar-ms Dec 17, 2025
a272af9
Merge remote-tracking branch 'origin/main' into riedgar-ms/selfask-sc…
riedgar-ms Dec 17, 2025
eee44be
Need a doc string
riedgar-ms Dec 17, 2025
41f576c
Forgot doc hook
riedgar-ms Dec 17, 2025
955ce14
Merge remote-tracking branch 'origin/main' into riedgar-ms/selfask-sc…
riedgar-ms Dec 22, 2025
5c53356
Address ruff issues
riedgar-ms Dec 22, 2025
8b746d5
Merge remote-tracking branch 'origin/main' into riedgar-ms/selfask-sc…
riedgar-ms Dec 28, 2025
3cd53b2
Resolve transpondian confusion
riedgar-ms Dec 28, 2025
489b897
Fixing merge
riedgar-ms Dec 29, 2025
b9faa93
Merge remote-tracking branch 'origin/main' into riedgar-ms/selfask-sc…
riedgar-ms Dec 30, 2025
7aee618
Don't need to quote self in type annotation
riedgar-ms Dec 30, 2025
5ebe871
Fix indent in docstring
riedgar-ms Dec 30, 2025
fb9ebc0
Put links in docstring
riedgar-ms Dec 30, 2025
97b64e3
Better naming
riedgar-ms Dec 30, 2025
b5cc797
Update tests
riedgar-ms Dec 30, 2025
3ad5b7d
blacken
riedgar-ms Dec 30, 2025
91a88b8
Another blacken
riedgar-ms Dec 30, 2025
ee160f9
Python 3.10 grrrr....
riedgar-ms Dec 30, 2025
573d13b
Run isort
riedgar-ms Dec 30, 2025
ee0eb39
Drafting a notebook update
riedgar-ms Dec 30, 2025
6b2dd82
Update notebook
riedgar-ms Dec 30, 2025
560d4e9
Moving JsonResponseConfig to private
riedgar-ms Dec 30, 2025
406c7b7
Run isort on notebook
riedgar-ms Dec 30, 2025
5edfd65
Add section on JSON to the chat notebook
riedgar-ms Dec 30, 2025
ceb512d
Get the notebook fixed and regenerated
riedgar-ms Dec 30, 2025
693ced5
Fix OpenAI docs issue
riedgar-ms Dec 30, 2025
75f7e31
Linting notebooks
riedgar-ms Dec 30, 2025
2481ca6
Try running pre-commit
riedgar-ms Dec 30, 2025
e75d561
exec notebooks
romanlutz Dec 30, 2025
f2eae6c
Merge branch 'riedgar-ms/selfask-scorer-fix-01' of https://github.com…
romanlutz Dec 30, 2025
c2cce69
rerun notebooks and pre-commit
romanlutz Dec 30, 2025
d6e0c7b
Switch auth back for tests
riedgar-ms Dec 30, 2025
4f7c536
Merge remote-tracking branch 'origin/main' into riedgar-ms/selfask-sc…
riedgar-ms Dec 30, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions build_scripts/check_links.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
"https://platform.openai.com/docs/api-reference/introduction", # blocks python requests
"https://platform.openai.com/docs/api-reference/responses", # blocks python requests
"https://platform.openai.com/docs/guides/function-calling", # blocks python requests
"https://platform.openai.com/docs/guides/structured-outputs", # blocks python requests
"https://www.anthropic.com/research/many-shot-jailbreaking", # blocks python requests
"https://code.visualstudio.com/docs/devcontainers/containers",
"https://stackoverflow.com/questions/77134272/pip-install-dev-with-pyproject-toml-not-working",
Expand Down
96 changes: 95 additions & 1 deletion doc/code/targets/1_openai_chat_target.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,15 @@
"id": "1",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Found default environment files: ['/home/vscode/.pyrit/.env', '/home/vscode/.pyrit/.env.local']\n",
"Loaded environment file: /home/vscode/.pyrit/.env\n",
"Loaded environment file: /home/vscode/.pyrit/.env.local\n"
]
},
{
"name": "stdout",
"output_type": "stream",
Expand Down Expand Up @@ -88,6 +97,91 @@
"cell_type": "markdown",
"id": "2",
"metadata": {},
"source": [
"## JSON Output\n",
"\n",
"You can also get the output in JSON format for further processing or storage. In this example, we define a simple JSON schema that describes a person with `name` and `age` properties.\n",
"\n",
"For more information about structured outputs with OpenAI, see [the OpenAI documentation](https://platform.openai.com/docs/guides/structured-outputs)."
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "3",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Found default environment files: ['/home/vscode/.pyrit/.env', '/home/vscode/.pyrit/.env.local']\n",
"Loaded environment file: /home/vscode/.pyrit/.env\n",
"Loaded environment file: /home/vscode/.pyrit/.env.local\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"{\n",
" \"name\": \"Bob\",\n",
" \"age\": 32\n",
"}\n"
]
}
],
"source": [
"import json\n",
"\n",
"import jsonschema\n",
"\n",
"from pyrit.models import Message, MessagePiece\n",
"from pyrit.prompt_target import OpenAIChatTarget\n",
"from pyrit.setup import IN_MEMORY, initialize_pyrit_async\n",
"\n",
"await initialize_pyrit_async(memory_db_type=IN_MEMORY) # type: ignore\n",
"\n",
"# Define a simple JSON schema for a person\n",
"person_schema = {\n",
" \"type\": \"object\",\n",
" \"properties\": {\n",
" \"name\": {\"type\": \"string\"},\n",
" \"age\": {\"type\": \"integer\", \"minimum\": 0, \"maximum\": 150},\n",
" },\n",
" \"required\": [\"name\", \"age\"],\n",
" \"additionalProperties\": False,\n",
"}\n",
"\n",
"prompt = \"Create a JSON object describing a person named Bob who is 32 years old.\"\n",
"# Create the message piece and message\n",
"message_piece = MessagePiece(\n",
" role=\"user\",\n",
" original_value=prompt,\n",
" original_value_data_type=\"text\",\n",
" prompt_metadata={\n",
" \"response_format\": \"json\",\n",
" \"json_schema\": json.dumps(person_schema),\n",
" },\n",
")\n",
"message = Message(message_pieces=[message_piece])\n",
"\n",
"# Create the OpenAI Chat target\n",
"target = OpenAIChatTarget()\n",
"\n",
"# Send the prompt, requesting JSON output\n",
"response = await target.send_prompt_async(message=message) # type: ignore\n",
"\n",
"# Validate and print the response\n",
"response_json = json.loads(response[0].message_pieces[0].converted_value)\n",
"print(json.dumps(response_json, indent=2))\n",
"jsonschema.validate(instance=response_json, schema=person_schema)"
]
},
{
"cell_type": "markdown",
"id": "4",
"metadata": {},
"source": [
"## OpenAI Configuration\n",
"\n",
Expand Down Expand Up @@ -125,7 +219,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.11.13"
"version": "3.11.14"
}
},
"nbformat": 4,
Expand Down
53 changes: 53 additions & 0 deletions doc/code/targets/1_openai_chat_target.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,59 @@
result = await attack.execute_async(objective=jailbreak_prompt) # type: ignore
await ConsoleAttackResultPrinter().print_conversation_async(result=result) # type: ignore

# %% [markdown]
# ## JSON Output

# You can also get the output in JSON format for further processing or storage. In this example, we define a simple JSON schema that describes a person with `name` and `age` properties.
#
# For more information about structured outputs with OpenAI, see [the OpenAI documentation](https://platform.openai.com/docs/guides/structured-outputs).

# %%
import json

import jsonschema

from pyrit.models import Message, MessagePiece
from pyrit.prompt_target import OpenAIChatTarget
from pyrit.setup import IN_MEMORY, initialize_pyrit_async

await initialize_pyrit_async(memory_db_type=IN_MEMORY) # type: ignore

# Define a simple JSON schema for a person
person_schema = {
"type": "object",
"properties": {
"name": {"type": "string"},
"age": {"type": "integer", "minimum": 0, "maximum": 150},
},
"required": ["name", "age"],
"additionalProperties": False,
}

prompt = "Create a JSON object describing a person named Bob who is 32 years old."
# Create the message piece and message
message_piece = MessagePiece(
role="user",
original_value=prompt,
original_value_data_type="text",
prompt_metadata={
"response_format": "json",
"json_schema": json.dumps(person_schema),
},
)
message = Message(message_pieces=[message_piece])

# Create the OpenAI Chat target
target = OpenAIChatTarget()

# Send the prompt, requesting JSON output
response = await target.send_prompt_async(message=message) # type: ignore

# Validate and print the response
response_json = json.loads(response[0].message_pieces[0].converted_value)
print(json.dumps(response_json, indent=2))
jsonschema.validate(instance=response_json, schema=person_schema)

# %% [markdown]
# ## OpenAI Configuration
#
Expand Down
Loading