github/copilot-sdk · error · ValueError
Missing required fields in ModelPolicy: state=
Error message
Missing required fields in ModelPolicy: state={state}, terms={terms} What it means
ModelPolicy.from_dict requires both 'state' and 'terms' keys in a model's policy object and raises ValueError when either is missing/None. The library models per-model policy (enablement state plus terms) as mandatory so downstream code can rely on both values.
Solutions
- Update the server/client versions so model policy payloads include both 'state' and 'terms'
- Filter or skip models whose policy payload is incomplete before decoding
- Fix fixtures/mocks to include a complete policy: {'state': ..., 'terms': ...}
Example fix
// before (mock)
{"policy": {"state": "enabled"}}
// after
{"policy": {"state": "enabled", "terms": "https://example.com/terms"}} Defensive patterns
Strategy: validation
Validate before calling
def is_complete_model_policy(p: dict | None) -> bool:
return isinstance(p, dict) and p.get("state") is not None and p.get("terms") is not None Type guard
def has_model_policy(model: dict) -> bool:
p = model.get("policy")
return isinstance(p, dict) and "state" in p and "terms" in p Try / catch
try:
policy = ModelPolicy.from_dict(model["policy"])
except ValueError as e:
if str(e).startswith("Missing required fields in ModelPolicy"):
policy = None # treat model as policy-less
else:
raise Prevention
- Validate model-catalog entries before batch decoding
- Skip models with incomplete policy objects rather than failing the whole list
- Pin client/server versions so the model-policy schema matches
When it happens
Trigger: The models/list response contains a model whose 'policy' object lacks 'state' or 'terms'; a server or mock emits policy as {} or with only one key.
Common situations: Newer/older server builds with a changed model-policy schema; models listed in preview states that omit terms; cached or mocked model catalogs in tests.
Understand the failure class
Background: Schema validation failed / invalid input schema: payload rejected because its shape doesn't match the expected schema — this error's family across 28 libraries.
Related errors
- Missing required fields in PingResponse: message=
- Missing required field 'message' in StopError
- Missing required fields in GetStatusResponse: version=
- Missing required field 'isAuthenticated' in…
- Missing required fields in ModelInfo: id=
AI-assisted analysis of github/copilot-sdk@cd8cf15dc3 (2026-09-09).
Data as JSON: /api/errors/71ae25b59ae994ee.
Report an issue: GitHub.
Appendix: source
Thrown at python/copilot/client.py:1084
result["supports"] = self.supports.to_dict()
result["limits"] = self.limits.to_dict()
return result
@dataclass
class ModelPolicy:
"""Model policy state"""
state: str # "enabled", "disabled", or "unconfigured"
terms: str
@staticmethod
def from_dict(obj: Any) -> ModelPolicy:
assert isinstance(obj, dict)
state = obj.get("state")
terms = obj.get("terms")
if state is None or terms is None:
raise ValueError(
f"Missing required fields in ModelPolicy: state={state}, terms={terms}"
)
return ModelPolicy(state=str(state), terms=str(terms))
def to_dict(self) -> dict:
result: dict = {}
result["state"] = self.state
result["terms"] = self.terms
return result
@dataclass
class ModelBilling:
"""Model billing information"""
multiplier: float | None = None
token_prices: ModelBillingTokenPrices | None = None
View on GitHub (pinned to cd8cf15dc3)