PromptedSchema(inner: ResponseProto[T], /, *, prompt_template: str | None = None)
PromptedSchema(inner: type[T], /, *, prompt_template: str | None = None)
PromptedSchema(inner: ClassInfo, /, *, prompt_template: str | None = None)
PromptedSchema(inner, /, *, prompt_template=None)
Bases: ResponseProto[T]
Response schema that uses prompt-based instructions instead of native API structured output.
Use this for models or providers that do not support built-in structured output (e.g., response_format). The JSON schema is injected into the system prompt, instructing the model to return valid JSON matching the schema. Validation is still performed using the inner schema's validate method.
Examples:
Using with a type directly::
agent = Agent(..., response_schema=PromptedSchema(MyModel))
Wrapping an existing ResponseProto::
schema = ResponseSchema(int | str)
agent = Agent(..., response_schema=PromptedSchema(schema))
Source code in autogen/beta/response/prompted.py
| def __init__(
self,
inner: "ResponseProto[T] | type[T] | ClassInfo",
/,
*,
prompt_template: str | None = None,
) -> None:
self._inner = ResponseSchema[T].ensure_schema(inner)
self.name = self._inner.name
self.description = self._inner.description
self._json_schema = self._inner.json_schema
self._prompt_template = prompt_template or _DEFAULT_PROMPT_TEMPLATE
if self._json_schema:
schema_str = json.dumps(self._json_schema, indent=2)
self.system_prompt = self._prompt_template.format(schema=schema_str)
else:
self.system_prompt = None
# Set public property to None to avoid native JSON schema validation
self.json_schema = None
|
description instance-attribute
description = description
system_prompt instance-attribute
system_prompt = format(schema=schema_str)
json_schema instance-attribute
validate async
validate(response, context, provider=None)
Source code in autogen/beta/response/prompted.py
| async def validate(
self,
response: str,
context: "Context",
provider: "Provider | None" = None,
) -> T:
return await self._inner.validate(response, context, provider)
|