Skip to content

Add guidelines to chat.create - #229

Merged
Omar-V2 merged 4 commits into
xai-org:mainfrom
rokujix:feat/guidelines
Oct 23, 2026
Merged

Omar-V2 merged 4 commits into
xai-org:mainfrom
rokujix:feat/guidelines

Conversation

@rokujix

@rokujix rokujix commented Oct 21, 2026

Copy link
Copy Markdown
Contributor

client.chat.create (sync and async) takes a guidelines list for
custom moderation controls and sets GetCompletionsRequest.guidelines
(field 39). Each entry is a Guideline dict in the REST shape,
{"type": "policy", "category": ..., "behavior": ...}, or a
chat_pb2.Guideline. An unknown category or behavior raises
ValueError. The API rejects an unsupported pair, a repeated category,
or a model that cannot apply guidelines with INVALID_ARGUMENT.

The v5 and v6 chat_pb2 stubs are regenerated with xai-proto's
buf.gen.yaml from the proto state the vendored stubs match (xai-proto
#73 plus safety_identifier) plus the guideline definitions. Before the
change, that pipeline reproduces the vendored stubs except for the
from . import rewrite.

Depends on xai-org/xai-proto#80, which adds GetCompletionsRequest.guidelines.

@rokujix
rokujix requested a review from a team as a code owner October 21, 2026 04:47
`client.chat.create` (sync and async) takes a `guidelines` list for
custom moderation controls and sets `GetCompletionsRequest.guidelines`
(field 39). Each entry is a `Guideline` dict in the REST shape,
`{"type": "policy", "category": ..., "behavior": ...}`, or a
`chat_pb2.Guideline`. An unknown category or behavior raises
`ValueError`. The API rejects an unsupported pair, a repeated category,
or a model that cannot apply guidelines with `INVALID_ARGUMENT`.

The v5 and v6 `chat_pb2` stubs are regenerated with xai-proto's
`buf.gen.yaml` from the proto state the vendored stubs match (xai-proto
xai-org#73 plus `safety_identifier`) plus the guideline definitions. Before the
change, that pipeline reproduces the vendored stubs except for the
`from . import` rewrite.

Depends on the xai-proto change that adds `GetCompletionsRequest.guidelines`.
Omar-V2
Omar-V2 previously approved these changes Oct 21, 2026
Regenerates only the guideline enums in the v5 and v6 chat stubs.
@deanrie

deanrie commented Oct 23, 2026

Copy link
Copy Markdown

Hey @rokujix, one line for the reviewer: the dependency named in the description, xai-org/xai-proto#80, merged on 2026-10-21 at 18:16 UTC, about fourteen hours after this PR was opened, so the vendored chat_pb2 stubs should now be checked against a regeneration from that merge commit rather than from the pre-merge branch. If they match byte for byte except the from . import rewrite you mention, the proto side of this is settled and what remains is the chat.py / types / tests review; if they differ in the Guideline message or field 39, the regeneration is the fix.

@Omar-V2
Omar-V2 merged commit eb37731 into xai-org:main Oct 23, 2026
7 checks passed
Omar-V2 added a commit that referenced this pull request Oct 23, 2026
Prepare to release `v1.21.0` of the xAI Python SDK following the
addition of safety_identifier (#221), guidelines (#229) and protobuf 7
support (#223).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants